129 lines
4.3 KiB
PHP
129 lines
4.3 KiB
PHP
<?php
|
|
/**
|
|
* ThinkShop商城系统 - 团队十年电商经验汇集巨献!
|
|
* =========================================================
|
|
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
|
|
* ----------------------------------------------
|
|
* 官方网址: https://www.cdcloudshop.com
|
|
* =========================================================
|
|
*/
|
|
|
|
namespace addon\store\model\cashier;
|
|
|
|
use app\model\BaseModel;
|
|
use app\model\member\Hongbao;
|
|
use app\model\member\MemberAccount;
|
|
use app\model\member\MemberCoupon;
|
|
|
|
/**
|
|
* 常规订单操作
|
|
*
|
|
* @author Administrator
|
|
*
|
|
*/
|
|
class CashierOrderReward extends BaseModel
|
|
{
|
|
|
|
|
|
/**
|
|
* 增加订单赠送项
|
|
* @param $params
|
|
* @return array
|
|
*/
|
|
public function addOrderReward($params){
|
|
$order_id = $params['order_id'];
|
|
$type = $params['type'];
|
|
$num = $params['num'];
|
|
$relate_id = $params['relate_id'] ?? 0;
|
|
$member_id = $params['member_id'];
|
|
$promotion_type = $params['promotion_type'];
|
|
$site_id = $params['site_id'];
|
|
$promotion_id = $params['promotion_id'];
|
|
$order_goods_id = $params['order_goods_id'] ?? '';
|
|
$status = $params['status'] ?? 0;
|
|
$desc = $params['desc'];
|
|
$data = array(
|
|
'order_id' => $order_id,
|
|
'promotion_type' => $promotion_type,
|
|
'promotion_id' => $promotion_id,
|
|
'type' => $type,
|
|
'num' => $num,
|
|
'site_id' => $site_id,
|
|
'relate_id' => $relate_id,
|
|
'order_goods_id' => $order_goods_id,
|
|
'status' => $params['status'] ?? 0,
|
|
'member_id' => $member_id,
|
|
'status' => $status,
|
|
'desc' => $desc
|
|
);
|
|
model('store_cashier_order_reward')->add($data);
|
|
return $this->success();
|
|
}
|
|
|
|
/**
|
|
* 获取优惠券记录
|
|
* @param $condition
|
|
* @param string $field
|
|
*/
|
|
public function getOrderRewardList($condition, $field = '*', $order = ''){
|
|
$list = model('store_cashier_order_reward')->getList($condition, $field, $order);
|
|
return $this->success($list);
|
|
}
|
|
|
|
|
|
/**
|
|
* 发放订单奖励
|
|
* @param $params
|
|
*/
|
|
public function grantOrderReward($params){
|
|
$order_id = $params['order_id'] ?? 0;
|
|
if($order_id > 0) {
|
|
$site_id = $params['site_id'];
|
|
$member_id= $params['member_id'];
|
|
$condition = array(
|
|
['order_id', '=', $order_id],
|
|
['status', '=', 0]
|
|
);
|
|
|
|
$reward_list = $this->getOrderRewardList($condition)['data'] ?? [];
|
|
if (!empty($reward_list)) {
|
|
//已关闭的订单想就不能发放相关的奖励了
|
|
$close_goods_ids = model('store_cashier_order_goods')->getValue([['order_id', '=', $order_id], ['order_goods_status', '=', 'close']], 'order_goods_id');
|
|
|
|
foreach ($reward_list as $k => $v) {
|
|
if(!empty($close_goods_ids)){//已关闭就不要发了,可能会修改状态
|
|
$item_order_goods_ids = $v['order_goods_id'];
|
|
if(empty($item_order_goods_ids))
|
|
continue;
|
|
$item_order_goods_ids = explode(',', $item_order_goods_ids);
|
|
$temp_intersect = array_intersect($item_order_goods_ids,$close_goods_ids);
|
|
if(empty($temp_intersect))
|
|
continue;
|
|
}
|
|
$v['member_id'] = $member_id;
|
|
$v['site_id'] = $site_id;
|
|
//调用钩子发放奖励
|
|
$result = event('CashierOrderRewardGrant', $v, true);
|
|
if(!empty($result)){
|
|
if($result['code'] < 0)
|
|
return $result;
|
|
}else{
|
|
|
|
}
|
|
//修改状态
|
|
$temp_data = array(
|
|
'status' => 1
|
|
);
|
|
$temp_condition = array(
|
|
['order_reward_id', '=', $v['order_reward_id']]
|
|
);
|
|
model('store_cashier_order_reward')->update($temp_data, $temp_condition);
|
|
}
|
|
|
|
}
|
|
return $this->success();
|
|
}
|
|
return $this->error();
|
|
}
|
|
|
|
} |