1142 lines
27 KiB
PHP
1142 lines
27 KiB
PHP
<?php
|
|
namespace app\shop\model;
|
|
|
|
use app\BaseModel;
|
|
use app\farm\model\BalanceWater;
|
|
use app\farm\model\Config;
|
|
use app\farm\model\Coupon;
|
|
use app\farm\model\CouponRecord;
|
|
|
|
use app\farm\model\User;
|
|
use app\publics\model\TmplConfig;
|
|
use longbingcore\wxcore\WxTmpl;
|
|
use think\facade\Db;
|
|
|
|
class ShopOrder extends BaseModel
|
|
{
|
|
//定义表名
|
|
protected $name = 'lbfarm_shop_order';
|
|
|
|
|
|
protected $append = [
|
|
|
|
'order_goods',
|
|
//
|
|
'all_goods_num',
|
|
|
|
'address_info',
|
|
|
|
'hx_user_name',
|
|
|
|
'store_info',
|
|
|
|
'farmer_info',
|
|
|
|
'distance_text'
|
|
|
|
];
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2022-03-08 11:00
|
|
* @功能说明:
|
|
*/
|
|
public function getDistanceTextAttr($value,$data){
|
|
|
|
if(!empty($data['distance'])){
|
|
|
|
return distance_text($data['distance']);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2022-03-07 17:38
|
|
* @功能说明:
|
|
*/
|
|
public function getStoreInfoAttr($value,$data){
|
|
|
|
if(!empty($data['store_id'])){
|
|
|
|
$farmer_model= new Farmer();
|
|
|
|
$info = $farmer_model->dataInfo(['id'=>$data['store_id'],'type'=>2]);
|
|
|
|
return $info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2022-03-07 17:38
|
|
* @功能说明:
|
|
*/
|
|
public function getFarmerInfoAttr($value,$data){
|
|
|
|
if(!empty($data['farmer_id'])){
|
|
|
|
$farmer_model= new Farmer();
|
|
|
|
$info = $farmer_model->dataInfo(['id'=>$data['farmer_id'],'type'=>1]);
|
|
|
|
return $info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-11-10 17:08
|
|
* @功能说明:核销人
|
|
*/
|
|
public function getHxUserNameAttr($value,$data){
|
|
|
|
if(isset($data['hx_user'])){
|
|
|
|
if(!empty($data['hx_user'])){
|
|
|
|
$user_model = new User();
|
|
|
|
$name = $user_model->where(['id'=>$data['hx_user']])->value('nickName');
|
|
|
|
return $name;
|
|
|
|
}else{
|
|
|
|
return '自动收货';
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @param $value
|
|
* @param $data
|
|
* @功能说明:地址信息
|
|
* @author chenniang
|
|
* @DataTime: 2021-04-08 10:11
|
|
*/
|
|
public function getAddressInfoAttr($value,$data){
|
|
|
|
if(!empty($data['id'])){
|
|
|
|
$address_model = new OrderAddress();
|
|
|
|
$address_info = $address_model->dataInfo(['order_id'=>$data['id'],'type'=>5]);
|
|
|
|
return $address_info;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @param $value
|
|
* @param $data
|
|
* @功能说明:总商品数量
|
|
* @author chenniang
|
|
* @DataTime: 2021-03-25 14:39
|
|
*/
|
|
public function getAllGoodsNumAttr($value,$data){
|
|
|
|
if(!empty($data['id'])){
|
|
|
|
$order_goods_model = new ShopOrderGoods();
|
|
|
|
$dis = [
|
|
|
|
'order_id' => $data['id']
|
|
];
|
|
|
|
$num = $order_goods_model->where($dis)->sum('goods_num');
|
|
|
|
return $num;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-03-19 17:05
|
|
* @功能说明:子订单信息
|
|
*/
|
|
|
|
public function getOrderGoodsAttr($value,$data){
|
|
|
|
if(!empty($data['id'])){
|
|
|
|
$order_goods_model = new ShopOrderGoods();
|
|
|
|
$dis = [
|
|
|
|
'order_id' => $data['id']
|
|
];
|
|
|
|
$list = $order_goods_model->where($dis)->select()->toArray();
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-03-25 17:40
|
|
* @功能说明:生产二维码
|
|
*/
|
|
public function getQrAttr($value,$data){
|
|
|
|
if(!empty($value)){
|
|
|
|
return $value;
|
|
}
|
|
|
|
if(!empty($data['pay_type'])&&$data['pay_type']>1&&!empty($data['id'])&&!empty($data['uniacid'])){
|
|
|
|
$qr_insert = [
|
|
|
|
'id' => $data['id']
|
|
];
|
|
|
|
$qr = $this->orderQr($qr_insert,$data['uniacid']);
|
|
|
|
if(!empty($qr)){
|
|
|
|
$this->dataUpdate(['id'=>$data['id']],['qr'=>$qr]);
|
|
|
|
return $qr;
|
|
}
|
|
|
|
return '';
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-10-27 15:42
|
|
* @功能说明:订单自提码
|
|
*/
|
|
public function orderQr($input,$uniacid){
|
|
|
|
$data = longbingCreateWxCode($uniacid,$input,'shop/pages/order/hexiao');
|
|
|
|
$data = transImagesOne($data ,['qr_path'] ,$uniacid);
|
|
|
|
$qr = $data['qr_path'];
|
|
|
|
return $qr;
|
|
}
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-03-19 16:23
|
|
* @功能说明:前端订单列表
|
|
*/
|
|
|
|
public function indexDataList($dis,$mapor,$page=10){
|
|
|
|
$data = $this->alias('a')
|
|
->join('lbfarm_shop_order_goods b','a.id = b.order_id')
|
|
->where($dis)
|
|
->where(function ($query) use ($mapor){
|
|
$query->whereOr($mapor);
|
|
})
|
|
->field('a.*')
|
|
->group('a.id')
|
|
->order('a.id desc')
|
|
->paginate($page)
|
|
->toArray();
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-03-15 14:37
|
|
* @功能说明:后台列表
|
|
*/
|
|
public function adminDataList($dis,$page=10){
|
|
|
|
$data = $this->alias('a')
|
|
->join('lbfarm_shop_order_goods c','a.id = c.order_id')
|
|
->join('lbfarm_order_address d','a.id = d.order_id AND d.type=5')
|
|
->where($dis)
|
|
->field('a.*,d.mobile,d.user_name')
|
|
->group('a.id')
|
|
->order('a.id desc')
|
|
->paginate($page)
|
|
->toArray();
|
|
|
|
if(!empty($data['data'])){
|
|
|
|
$user_model = new User();
|
|
|
|
foreach ($data['data'] as &$v){
|
|
|
|
$v['nickName'] = $user_model->where(['id'=>$v['user_id']])->value('nickName');
|
|
|
|
}
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-03-15 14:37
|
|
* @功能说明:后台列表
|
|
*/
|
|
public function adminDataSelect($dis){
|
|
|
|
$data = $this->alias('a')
|
|
->join('lbfarm_shop_order_goods c','a.id = c.order_id')
|
|
->join('lbfarm_order_address d','a.id = d.order_id AND d.type=5')
|
|
->where($dis)
|
|
->field('a.*,d.mobile,d.user_name')
|
|
->group('a.id')
|
|
->order('a.id desc')
|
|
->select()
|
|
->toArray();
|
|
|
|
if(!empty($data)){
|
|
|
|
$user_model = new User();
|
|
|
|
foreach ($data as &$v){
|
|
|
|
$v['nickName'] = $user_model->where(['id'=>$v['user_id']])->value('nickName');
|
|
|
|
}
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-09-29 11:04
|
|
* @功能说明:添加
|
|
*/
|
|
public function dataAdd($data){
|
|
|
|
$data['create_time'] = time();
|
|
|
|
$res = $this->insert($data);
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-09-29 11:05
|
|
* @功能说明:编辑
|
|
*/
|
|
public function dataUpdate($dis,$data){
|
|
|
|
$res = $this->where($dis)->update($data);
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-09-29 11:06
|
|
* @功能说明:列表
|
|
*/
|
|
public function dataList($dis,$page=10){
|
|
|
|
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-09-29 11:43
|
|
* @功能说明:
|
|
*/
|
|
public function dataInfo($dis){
|
|
|
|
$data = $this->where($dis)->find();
|
|
|
|
return !empty($data)?$data->toArray():[];
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-03-18 14:33
|
|
* @功能说明:
|
|
*/
|
|
public function datePrice($date,$uniacid,$cap_id=0,$end_time = '',$type=1){
|
|
|
|
$end_time = !empty($end_time)?$end_time:$date+86399;
|
|
|
|
$dis = [];
|
|
|
|
$dis[] = ['transaction_id','<>',''];
|
|
|
|
$dis[] = ['auto_refund','=',0];
|
|
|
|
$dis[] = ['create_time','between',"$date,$end_time"];
|
|
|
|
$dis[] = ['uniacid',"=",$uniacid];
|
|
|
|
if(!empty($cap_id)){
|
|
|
|
$dis[] = ['cap_id','=',$cap_id];
|
|
}
|
|
|
|
if($type==1){
|
|
|
|
$price = $this->where($dis)->sum('pay_price');
|
|
|
|
return round($price,2);
|
|
|
|
}else{
|
|
|
|
$count = $this->where($dis)->count();
|
|
|
|
return $count;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-03-19 09:28
|
|
* @功能说明:计算用户下单时候的各类金额
|
|
*/
|
|
public function payOrderInfo($user_id,$store_id,$coupon=0,$address_id=0,$is_show=1,$send_type=2){
|
|
|
|
$car_model = new Car();
|
|
//获取购物车里面的信息
|
|
$car_list = $car_model->carPriceAndCount($user_id,$store_id,0,$is_show);
|
|
|
|
$coupon_model = new Coupon();
|
|
|
|
$car_list = $coupon_model->orderCouponData($car_list,$coupon,2);
|
|
|
|
$address_model = new Address();
|
|
|
|
$config_model = new Config();
|
|
|
|
$address = $address_model->dataInfo(['id'=>$address_id]);
|
|
|
|
if(!empty($car_list['list'])){
|
|
|
|
foreach ($car_list['list'] as &$value){
|
|
|
|
if(!empty($address_id)&&$send_type==2){
|
|
|
|
$distance = getdistance($value['farmer_info']['lng'],$value['farmer_info']['lat'],$address['lng'],$address['lat']);
|
|
|
|
$value['distance'] = $distance;
|
|
//计算运费
|
|
$value['freight'] = $config_model->getSendPrice(round($distance/1000,2),$value['farmer_info']['uniacid']);
|
|
|
|
}else{
|
|
|
|
$value['distance'] = 0;
|
|
|
|
}
|
|
|
|
$value['distance_text'] = distance_text($value['distance']);
|
|
//商品总价格
|
|
$value['goods_price'] = round($value['car_price']-$value['coupon_discount'],2);
|
|
//订单支付价
|
|
$value['pay_price'] = round($value['goods_price']+$value['freight'] ,2);
|
|
|
|
$value['init_goods_price'] = round($value['init_price'] ,2);
|
|
//订单总价格
|
|
$value['init_price'] = round($value['init_price']+$value['freight'] ,2);
|
|
|
|
}
|
|
}
|
|
|
|
$coupon = !empty($car_list['car_price'])?$coupon:0;
|
|
|
|
$data['coupon_id'] = $coupon;
|
|
//购物车列表
|
|
$data['order_goods'] = $car_list['list'];
|
|
//商品总价格
|
|
$data['coupon_discount'] = round(array_sum(array_column($car_list['list'],'coupon_discount')),2);
|
|
|
|
$data['goods_price'] = round(array_sum(array_column($car_list['list'],'goods_price')),2);
|
|
|
|
$data['init_price'] = round(array_sum(array_column($car_list['list'],'init_price')),2);
|
|
|
|
$data['init_goods_price'] = round(array_sum(array_column($car_list['list'],'init_goods_price')),2);
|
|
|
|
$data['pay_price'] = round(array_sum(array_column($car_list['list'],'pay_price')),2);
|
|
|
|
$data['freight'] = round(array_sum(array_column($car_list['list'],'freight')),2);
|
|
|
|
$data['car_count'] = $car_list['car_count'];
|
|
|
|
return $data;
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-03-22 11:31
|
|
* @功能说明:订单支付回调
|
|
*/
|
|
public function orderResult($order_code,$transaction_id){
|
|
|
|
$order_list = $this->whereOr(['top_order_code'=>$order_code,'order_code'=>$order_code])->select()->toArray();
|
|
|
|
if(!empty($order_list)){
|
|
|
|
foreach ($order_list as $order){
|
|
|
|
if(!empty($order)&&$order['pay_type']==1){
|
|
|
|
Db::startTrans();
|
|
|
|
$update = [
|
|
|
|
'transaction_id' => $transaction_id,
|
|
|
|
'pay_type' => 2,
|
|
|
|
'pay_time' => time(),
|
|
|
|
];
|
|
|
|
$res = $this->dataUpdate(['id'=>$order['id']],$update);
|
|
|
|
if($res==0){
|
|
|
|
Db::rollback();
|
|
|
|
return false;
|
|
|
|
}
|
|
//扣除余额
|
|
if($order['balance']>0){
|
|
|
|
$water_model = new BalanceWater();
|
|
|
|
$res = $water_model->addWater($order,7,0);
|
|
|
|
if($res==0){
|
|
|
|
Db::rollback();
|
|
|
|
}
|
|
}
|
|
//添加流水
|
|
$water_model = new FinanceWater();
|
|
|
|
$water_model->addWater($order['id'],8,2,0);
|
|
//商城订单农场主获得运费
|
|
$water_model->addWater($order['id'],16,1,0);
|
|
|
|
Db::commit();
|
|
//发送订阅消息
|
|
$order['pay_time'] = $update['pay_time'];
|
|
|
|
$this->paySendService($order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2019-12-27 19:19
|
|
* @功能说明:发送订阅消息
|
|
*/
|
|
public function sendOrderService($order){
|
|
//获取用户的open_id
|
|
$user_model = new User();
|
|
|
|
$openid = $user_model->where(['id'=>$order['user_id']])->value('openid');
|
|
//访问页面
|
|
$page = 'shop/pages/order/detail?id='.$order['id'].'¬ice=1';
|
|
//模版消息model
|
|
$tmpl_model = new TmplConfig();
|
|
//获取模版
|
|
$tmpl = $tmpl_model->where([['uniacid','=',$order['uniacid']],['tmpl_name','=','send_order'],['tmpl_id','<>',0]])->find();
|
|
//如果未添加模版消息 则不发送
|
|
if(empty($tmpl)){
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
$tmpl = $tmpl->toArray();
|
|
}
|
|
//模版id
|
|
$tmpl_id = $tmpl['tmpl_id'];
|
|
// //模版类容
|
|
// $key_worlds = $tmpl['kidList'];
|
|
$service_model = new WxTmpl($order['uniacid']);
|
|
//模版的key
|
|
$key_worlds = $service_model::getTmplKey($tmpl_id);
|
|
|
|
if(!empty($openid)&&!empty($tmpl_id)&&!empty($key_worlds)){
|
|
//验证模版内容
|
|
if(!is_array($key_worlds)||count($key_worlds)<4){
|
|
return true;
|
|
}
|
|
$order['express_company'] = $service_model::strToUtf8($order['express_company']);
|
|
//发送内容
|
|
$send_data = array(
|
|
$key_worlds[1]=>array(
|
|
//发货时间物流公司
|
|
'value'=>date('Y-m-d H:i:s',$order['send_time']),
|
|
),
|
|
$key_worlds[2]=>array(
|
|
//订单编号
|
|
'value'=>$order['order_code'],
|
|
),
|
|
$key_worlds[3]=>array(
|
|
//物流编号
|
|
'value'=>$order['express_code'],
|
|
),
|
|
$key_worlds[4]=>array(
|
|
//
|
|
'value'=>$order['express_company'],
|
|
)
|
|
);
|
|
//模版消息库类
|
|
$tmpl_sever = new WxTmpl($order['uniacid']);
|
|
//发送模版消息
|
|
$res = $tmpl_sever::sendTmpl($openid,$tmpl_id,$send_data,$page);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2019-12-27 19:19
|
|
* @功能说明:发送订阅消息
|
|
*/
|
|
public function paySendService($order){
|
|
|
|
$user_model = new User();
|
|
//获取用户的open_id
|
|
$openid = $user_model->where(['id'=>$order['user_id']])->value('openid');
|
|
//访问页面
|
|
$page = 'shop/pages/order/detail?id='.$order['id'].'¬ice=1';
|
|
//模版消息model
|
|
$tmpl_model = new TmplConfig();
|
|
//获取模版
|
|
$tmpl = $tmpl_model->where(['uniacid'=>$order['uniacid'],'tmpl_name'=>'pay_order'])->find();
|
|
|
|
//如果未添加模版消息 则不发送
|
|
if(empty($tmpl)){
|
|
return true;
|
|
}else{
|
|
$tmpl = $tmpl->toArray();
|
|
}
|
|
//模版id
|
|
$tmpl_id = $tmpl['tmpl_id'];
|
|
// //模版类容
|
|
// $key_worlds = $tmpl['kidList'];
|
|
$service_model = new WxTmpl($order['uniacid']);
|
|
//模版的key
|
|
$key_worlds = $service_model::getTmplKey($tmpl_id);
|
|
|
|
if(!empty($openid)&&!empty($tmpl_id)&&!empty($key_worlds)){
|
|
//验证模版内容
|
|
if(!is_array($key_worlds)||count($key_worlds)<4){
|
|
|
|
return true;
|
|
}
|
|
|
|
$goods_names = implode(',',array_column($order['order_goods'],'goods_name'));
|
|
|
|
// $goods_name = msubstr($goods_names,0,18);
|
|
$goods_name = mb_substr($goods_names,0,18);
|
|
//发送内容
|
|
$send_data = array(
|
|
|
|
$key_worlds[1]=>array(
|
|
//商品名称
|
|
'value'=> $goods_name,
|
|
//'value'=>'圣女果小番茄--物流、自提,圣女果小番茄圣女果小番茄',
|
|
),
|
|
$key_worlds[2]=>array(
|
|
//商品价格
|
|
'value'=>$order['pay_price'].'元',
|
|
),
|
|
$key_worlds[3]=>array(
|
|
//支付金额
|
|
'value'=>$order['order_code'],
|
|
),
|
|
$key_worlds[4]=>array(
|
|
//支付时间
|
|
'value'=>date('Y-m-d H:i:s',$order['pay_time']),
|
|
),
|
|
);
|
|
//模版消息库类
|
|
$tmpl_sever = new WxTmpl($order['uniacid']);
|
|
//发送模版消息
|
|
$res = $tmpl_sever::sendTmpl($openid,$tmpl_id,$send_data,$page);
|
|
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-03-22 15:31
|
|
* @功能说明:团长冻结资金
|
|
*/
|
|
public function capFrozenPrice($cap_id,$total=0,$toDay=0){
|
|
|
|
$dis[] = ['cap_id','=',$cap_id];
|
|
|
|
if($total==0){
|
|
|
|
$dis[] = ['have_tx','=',0];
|
|
}
|
|
|
|
$dis[] = ['pay_type','>',1];
|
|
|
|
if($toDay==1){
|
|
//当日
|
|
$price = $this->where($dis)->whereDay('create_time')->sum('cap_price');
|
|
|
|
}else{
|
|
|
|
$price = $this->where($dis)->sum('cap_price');
|
|
|
|
}
|
|
|
|
return round($price,2);
|
|
|
|
}
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-03-22 15:31
|
|
* @功能说明:团长冻结资金
|
|
*/
|
|
public function capFrozenCount($cap_id,$total=0,$toDay=0){
|
|
|
|
$dis[] = ['cap_id','=',$cap_id];
|
|
|
|
if($total==0){
|
|
|
|
$dis[] = ['have_tx','=',0];
|
|
}
|
|
|
|
$dis[] = ['pay_type','>',1];
|
|
|
|
if($toDay==1){
|
|
//当日
|
|
$price = $this->where($dis)->whereDay('create_time')->count();
|
|
|
|
}else{
|
|
|
|
$price = $this->where($dis)->count();
|
|
|
|
}
|
|
|
|
return $price;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-03-22 15:41
|
|
* @功能说明:团长佣金到账
|
|
*/
|
|
public function capArrPrice($uniacid,$user_id=0){
|
|
|
|
$dis[] = ['uniacid','=',$uniacid];
|
|
|
|
$dis[] = ['pay_type','=',7];
|
|
|
|
if(!empty($user_id)){
|
|
|
|
$dis[] = ['user_id','=',$user_id];
|
|
}
|
|
|
|
$dis[] = ['have_tx','=',0];
|
|
|
|
$dis[] = ['can_refund_time','<',time()];
|
|
|
|
$order = $this->where($dis)->field('id,get_integral,user_id,uniacid,can_refund_time')->select()->toArray();
|
|
|
|
if(!empty($order)){
|
|
|
|
$refund_model = new RefundOrder();
|
|
|
|
$integral_model = new \app\member\model\Integral();
|
|
|
|
foreach ($order as $value){
|
|
//判断有无申请中的退款订单
|
|
$refund_order = $refund_model->dataInfo(['order_id'=>$value['id'],'status'=>1]);
|
|
|
|
if(empty($refund_order)){
|
|
//修改订单状态
|
|
$res = $this->where(['id'=>$value['id'],'have_tx'=>0])->update(['have_tx'=>1]);
|
|
//增加用户积分
|
|
if($res==1){
|
|
|
|
$integral_model->integralUserAdd($value['user_id'],$value['get_integral'],$value['uniacid'],2,10,$value['id'],$value['can_refund_time']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-03-26 15:15
|
|
* @功能说明:核销订单
|
|
*/
|
|
public function hxOrder($order_id,$cap_id=0,$uniacid=1,$time = 0){
|
|
|
|
$config_model = new Config();
|
|
|
|
$config = $config_model->dataInfo(['uniacid'=>$uniacid]);
|
|
|
|
$update = [
|
|
|
|
'hx_time' => !empty($time)?$time:time(),
|
|
|
|
'pay_type'=> 7,
|
|
|
|
'hx_user' => $cap_id,
|
|
//可申请退款的时间
|
|
'can_refund_time' => time()+$config['can_tx_time']*3600
|
|
|
|
];
|
|
|
|
$res = $this->dataUpdate(['id'=>$order_id],$update);
|
|
//修改佣金到账状态
|
|
$water_model = new FinanceWater();
|
|
|
|
$dis[] = ['type','in',[8,15,16]];
|
|
|
|
$dis[] = ['order_id','=',$order_id];
|
|
|
|
$res = $water_model->dataUpdate($dis,['cash_status'=>1,'cash_time'=>$update['can_refund_time']]);
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-04-01 10:13
|
|
* @功能说明:超时自动退款
|
|
*/
|
|
public function autoCancelOrder($uniacid,$user_id=0){
|
|
|
|
$dis[] = ['uniacid','=',$uniacid];
|
|
|
|
$dis[] = ['pay_type','=',1];
|
|
|
|
$dis[] = ['over_time','<',time()];
|
|
|
|
if(!empty($user_id)){
|
|
|
|
$dis[] = ['user_id','=',$user_id];
|
|
}
|
|
|
|
$order = $this->where($dis)->select()->toArray();
|
|
|
|
if(!empty($order)){
|
|
|
|
foreach ($order as $value){
|
|
|
|
$this->cancelOrder($value,1);
|
|
|
|
}
|
|
|
|
}
|
|
//自动核销订单
|
|
$this->autoHxOrder($uniacid);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-11-19 13:27
|
|
* @功能说明:自动核销订单
|
|
*/
|
|
public function autoHxOrder($uniacid){
|
|
//仅限快递
|
|
// $dis[] = ['send_type','=',2];
|
|
//已经发货
|
|
$dis[] = ['pay_type','=',3];
|
|
|
|
$dis[] = ['hx_over_time','<',time()];
|
|
|
|
$order = $this->where($dis)->select()->toArray();
|
|
|
|
if(!empty($order)){
|
|
|
|
foreach ($order as $value){
|
|
|
|
$this->hxOrder($value['id'],0,$uniacid,$value['hx_over_time']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-04-01 10:13
|
|
* @功能说明:退款
|
|
*/
|
|
public function cancelOrder($order,$auto_refund=0){
|
|
|
|
Db::startTrans();
|
|
|
|
$res = $this->dataUpdate(['id'=>$order['id'],'pay_type'=>1],['pay_type'=>-1,'auto_refund'=>$auto_refund,'cancel_time'=>time()]);
|
|
|
|
if($res!=1){
|
|
|
|
Db::rollback();
|
|
|
|
return ['code'=>500,'msg'=>'取消失败'];
|
|
}
|
|
|
|
$goods_model = new ShopGoods();
|
|
//退换库存
|
|
foreach ($order['order_goods'] as $v){
|
|
|
|
$res = $goods_model->setOrDelStock($v['goods_id'],$v['spe_id'],$v['goods_num'],1,0);
|
|
|
|
if(!empty($res['code'])){
|
|
|
|
Db::rollback();
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
}
|
|
// //退换优惠券
|
|
// $coupon_model = new CouponRecord();
|
|
//
|
|
// $coupon_model->couponRefund($order['id'],2);
|
|
|
|
Db::commit();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-11-03 11:11
|
|
* @功能说明:检查营销活动
|
|
*/
|
|
public function marketingCheck($data,$list){
|
|
//使用积分
|
|
if($data['integral']>0){
|
|
|
|
$user_model = new User();
|
|
|
|
$i_log = new \app\member\model\Integral();
|
|
|
|
$integral_model = new Integral();
|
|
|
|
$user = $user_model->dataInfo(['id'=>$data['user_id']]);
|
|
//检查用户积分
|
|
if($user['integral']<$data['integral']){
|
|
|
|
return ['code'=>500,'msg'=>'积分不足'];
|
|
}
|
|
|
|
|
|
foreach ($list as $value){
|
|
|
|
if(!empty($value['integral_id'])){
|
|
|
|
$atv = $integral_model->dataInfo(['id'=>$value['integral_id']]);
|
|
|
|
if(empty($atv)){
|
|
|
|
return ['code'=>500,'msg'=>'积分活动已下架'.$value['integral_id']];
|
|
|
|
}
|
|
|
|
$num = $integral_model->getAtvNum($value['integral_id'],$data['user_id']);
|
|
|
|
if($num>$atv['user_limit']){
|
|
|
|
return ['code'=>500,'msg'=>'该积分活动限购'.$atv['user_limit'].'次'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
//抵扣积分
|
|
$res = $i_log->integralUserAdd($data['user_id'],$data['integral']*-1,$data['uniacid'],2,3,$data['id']);
|
|
|
|
if($res==false){
|
|
|
|
return ['code'=>500,'msg'=>'积分抵扣失败'];
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2019-12-27 19:19
|
|
* @功能说明:发货发送订阅消息
|
|
*/
|
|
public function orderSendService($order){
|
|
|
|
$user_model = new User();
|
|
//获取用户的open_id
|
|
$openid = $user_model->where(['id'=>$order['user_id']])->value('openid');
|
|
//访问页面
|
|
$page = 'shop/pages/order/detail?id='.$order['id'].'¬ice=1';
|
|
//模版消息model
|
|
$tmpl_model = new TmplConfig();
|
|
//获取模版
|
|
$tmpl = $tmpl_model->where(['uniacid'=>$order['uniacid'],'tmpl_name'=>'send_order'])->find();
|
|
|
|
//如果未添加模版消息 则不发送
|
|
if(empty($tmpl)){
|
|
|
|
return true;
|
|
}else{
|
|
$tmpl = $tmpl->toArray();
|
|
}
|
|
//模版id
|
|
$tmpl_id = $tmpl['tmpl_id'];
|
|
//模版类容
|
|
$service_model = new WxTmpl($order['uniacid']);
|
|
//模版的key
|
|
$key_worlds = $service_model::getTmplKey($tmpl_id);
|
|
|
|
if(!empty($openid)&&!empty($tmpl_id)&&!empty($key_worlds)){
|
|
//验证模版内容
|
|
if(!is_array($key_worlds)||count($key_worlds)<4){
|
|
|
|
return true;
|
|
}
|
|
//发送内容
|
|
$send_data = array(
|
|
|
|
$key_worlds[1]=>array(
|
|
//商品名称
|
|
'value'=> date('Y-m-d H:i:s',$order['send_time']),
|
|
),
|
|
$key_worlds[2]=>array(
|
|
//订单编号
|
|
'value'=>$order['order_code'],
|
|
),
|
|
$key_worlds[3]=>array(
|
|
//物流编号
|
|
'value'=>$order['express_code'],
|
|
),
|
|
$key_worlds[4]=>array(
|
|
//物流公司
|
|
'value'=>$order['express_company'],
|
|
),
|
|
);
|
|
//模版消息库类
|
|
$tmpl_sever = new WxTmpl($order['uniacid']);
|
|
//发送模版消息
|
|
$res = $tmpl_sever::sendTmpl($openid,$tmpl_id,$send_data,$page);
|
|
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |