123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688 |
- <?php
- namespace app\api\controller;
- use AlibabaCloud\SDK\Vod\V20170321\Models\GetAIMediaAuditJobResponseBody\mediaAuditJob\data;
- use app\common\model\AfreshOrder;
- use app\common\model\AfreshOrderItem;
- use app\common\model\DeliveryAddress;
- use app\common\model\GoodsOrder;
- use app\common\model\StoreOrderRefund;
- use app\common\model\User;
- use app\common\model\UserCouponList;
- use app\common\model\WashOrder;
- use app\common\model\WashCate;
- use app\common\model\WashClothes;
- use app\common\model\WashOrderItem;
- use app\common\model\WashType;
- use app\common\service\OrderCallback;
- use think\Db;
- use think\Exception;
- /**
- * @title 洗涤管理
- * @controller WashManage
- * @group base
- */
- class WashManage extends Base
- {
- protected $module = 1;
- protected $need_login = [
- 'orderConfirm',
- 'createOrder',
- 'getOrderDetail',
- 'getOrderList',
- 'payOrder',
- 'cancelOrder',
- 'applyAfreshOrder',
- 'applyAfreshOrderDetail',
- 'cancelAfreshOrder',
- 'getAfreshOrderList',
- ];
- public function initialize()
- {
- parent::initialize();
- $this->module = input('module',1);
- if($this->user_id) {
- $cancel_list = WashOrder::where('user_id','=',$this->user_id)
- ->where('pay_state',0)
- ->where('cancel_state',0)
- ->where('create_at','<=',date("Y-m-d H:i:s",time() - 900))
- ->column('id');
- if(!empty($cancel_list)) {
- WashOrder::where('id','in',$cancel_list)->update(['cancel_state'=>1,'status'=>9,'cancel_desc'=>'系统自动取消']);
- }
- }
- }
- /**
- * @title 获取洗涤分类
- * @desc 获取洗涤分类
- * @author qc
- * @url /api/Wash_manage/getWashCate
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:module type:int default:1 desc:1洗鞋分类2洗衣分类
- * @return name:id type:int default:-- desc:分类id
- * @return name:title type:string default:-- desc:标题
- */
- public function getWashCate()
- {
- $all_cate = WashCate::getAllCateByModule($this->module);
- $this->success('ok',['list'=>$all_cate]);
- }
- /**
- * @title 获取洗涤商品【列表】
- * @desc 获取洗涤商品【列表】
- * @author qc
- * @url /api/Wash_manage/getGoodsList
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:module type:int default:1 desc:1洗鞋2洗衣
- * @param name:cate_id type:int default:1 desc:分类id(不传查洗鞋或洗衣全部的)
- * @return name:id type:int default:-- desc:id
- * @return name:name type:string default:-- desc:商品名
- * @return name:cover type:string default:-- desc:商品封面
- * @return name:price type:float default:-- desc:价格
- * @return name:wash_type_name type:string default:-- desc:洗涤类型名称
- */
- public function getGoodsList()
- {
- $cate_id = input('get.cate_id');
- $list = WashClothes::where(['c.module'=>$this->module,'c.status'=>1,'c.is_deleted'=>0])
- ->alias('c')
- ->field('c.*,t.title wash_type_name')
- ->leftJoin('WashType t','c.wash_type = t.id')
- ->when($cate_id,function ($query)use ($cate_id){
- if($cate_id) $query->where('c.cate_id',$cate_id);
- })->limit($this->off_set,$this->page_num)
- ->order('sort desc ,id desc')
- ->select()->toArray();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取商品详情
- * @desc 获取商品详情
- * @author qc
- * @url /api/Wash_manage/getGoodsDetail
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:module type:int default:1 desc:1洗鞋2洗衣
- * @return name:id type:int default:-- desc:id
- * @return name:name type:string default:-- desc:商品名
- * @return name:cover type:string default:-- desc:商品封面
- * @return name:price type:float default:-- desc:价格
- * @return name:wash_type_name type:string default:-- desc:洗涤类型名称
- */
- public function getGoodsDetail()
- {
- $goods_id = input('get.goods_id');
- $detail = WashClothes::where('id',$goods_id)->find()->toArray();
- if($detail['status'] == 0 || $detail['is_deleted'] == 1) $this->error('商品已下架');
- $detail['wash_type_name'] = WashType::where('id',$detail['wash_type'])->value('title');
- $this->success('获取成功',['detail'=>$detail]);
- }
- /**
- * @title 订单确认页数据
- * @desc 订单确认页数据
- * @author qc
- * @url /api/Wash_manage/orderConfirm
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:module type:int default:1 desc:1洗鞋2洗衣
- * @param name:goods_json type:string require:1 default:0 desc:商品json信息[{'goods_id':'商品id','num':'数量'}]
- * @return name:list type:array default:-- desc:商品列表
- * @return name:list.id type:int default:-- desc:商品id
- * @return name:list.name type:float default:-- desc:商品名
- * @return name:list.price type:float default:-- desc:商品价格
- * @return name:list.cover type:float default:-- desc:商品封面
- * @return name:list.cate_name type:float default:-- desc:所属分类名
- * @return name:list.wash_type_name type:float default:-- desc:洗涤类型名
- * @return name:list.buy_num type:float default:-- desc:选择数量
- * @return name:list.order_price type:float default:-- desc:该商品金额
- * @return name:price_total type:float default:-- desc:订单金额(包含取件费)
- * @return name:total_num type:int default:-- desc:总件数
- * @return name:postage type:int default:-- desc:取件费用
- * @return name:goods_price type:int default:-- desc:商品总费用
- * @return name:address type:array default:-- desc:默认售货地址
- * @return name:address.pro_name type:string require:1 default:-- desc:省名
- * @return name:address.city_name type:string require:1 default:-- desc:市名
- * @return name:address.county_name type:string require:1 default:-- desc:县区名
- * @return name:address.detail type:string require:1 default:-- desc:详细地址
- * @return name:address.phone type:string require:1 default:-- desc:联系电话
- * @return name:address.name type:string require:1 default:-- desc:联系人
- * @return name:address.sex type:int require:1 default:-- desc:性别(1男2女)
- */
- public function orderConfirm()
- {
- $goods_json = input('get.goods_json','');
- $goods_data = json_decode($goods_json,true);
- $goods_column = array_column($goods_data,null,'goods_id');
- $goods_ids = array_keys($goods_column);
- $list = WashClothes::field('a.id,a.price,a.name,a.cover,c.title cate_name,t.title wash_type_name,wash_type')
- ->alias('a')
- ->leftJoin('WashCate c','c.id = a.cate_id')
- ->leftJoin('WashType t','t.id = a.wash_type')
- ->where('a.id','in',$goods_ids)
- ->where('a.module','=',$this->module)
- ->select()->toArray();
- if(count($list) != count($goods_ids)) $this->error('商品信息有误');
- $price_total = 0;
- array_walk($list,function (&$v)use (&$price_total,$goods_column){
- $v['order_price'] = bcmul($v['price'],$goods_column[$v['id']]['num'],2);
- $v['buy_num'] = $goods_column[$v['id']]['num'];
- $price_total = bcadd($v['order_price'],$price_total,2);
- });
- $postage = sysconf('postage');
- $address = DeliveryAddress::field('id,pro_name,city_name,county_name,mer_name,detail,phone,name,sex')->where('user_id',$this->user_id)->where('is_mr',1)->find();
- $this->success('ok',[
- 'list'=>$list,
- 'goods_price'=>$price_total,
- 'price_total'=> bcadd($price_total,$postage,2),
- 'postage'=>$postage,
- 'total_num'=>array_sum(array_column($goods_data,'num')),
- 'address' => $address ? $address->toArray() : null,
- ]);
- }
- /**
- * @title 创建订单
- * @desc 创建订单
- * @author qc
- * @url /api/Wash_manage/createOrder
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:module type:int default:1 desc:1洗鞋2洗衣
- * @param name:goods_json type:string require:1 default:0 desc:商品json信息[{'goods_id':'商品id','num':'数量'}]
- * @param name:remark type:string default:-- desc:订单备注
- * @param name:images type:string default:-- desc:图片(多张|隔开)
- * @param name:address_id type:int default:-- desc:地址id
- * @param name:coupon_id type:int default:-- desc:优惠券id
- */
- public function createOrder()
- {
- $goods_json = input('post.goods_json','');
- $address_id = input('post.address_id','');
- $remark = input('post.remark','');
- $images = input('post.images','');
- $coupon_id = input('post.coupon_id','');
- $goods_data = json_decode($goods_json,true);
- $goods_column = array_column($goods_data,null,'goods_id');
- $goods_ids = array_keys($goods_column);
- if(!$address_id) $this->error('请选择售货地址');
- $list = WashClothes::field('a.id,a.price,a.cover,a.name,c.title cate_name,t.title wash_type_name,wash_type')
- ->alias('a')
- ->leftJoin('WashCate c','c.id = a.cate_id')
- ->leftJoin('WashType t','t.id = a.wash_type')
- ->where('a.id','in',$goods_ids)
- ->where('a.module','=',$this->module)
- ->select()->toArray();
- // $this->success('ok',['user_id'=>$this->user_id,'address_id'=>$address_id]);
- if(count($list) != count($goods_ids)) $this->error('商品信息有误');
- $postage = sysconf('postage');
- $ret_data = ['pay_status'=>0,'config'=>[],'order_id'=>0];
- Db::startTrans();
- try {
- $coupon_info = [];
- if($coupon_id) {
- $module = $this->module + 1;
- $coupon_info = UserCouponList::where(['l.user_id'=>$this->user_id,'l.status'=>1,'l.id'=>$coupon_id])
- ->alias('l.*,c.title,c.module,c.coupon_type,c.is_new')
- ->when($module,function ($query)use ($module){
- if($module > 1 ) $query->where('module','in','1,'. $module);
- })->leftJoin('CouponConfig c','c.id = l.coupon_id')
- ->find();
- if(empty($coupon_info)) $coupon_info = $this->exception('所选优惠券有误');
- $coupon_info = $coupon_info->toArray();
- }
- $address = DeliveryAddress::field('id,pro_name,city_name,county_name,mer_name,detail,phone,name,sex')
- ->where('user_id',$this->user_id)->where('id',$address_id)->find()->toArray();
- $price_total = 0;
- $order_info = [
- 'user_id' => $this->user_id,
- 'order_no' => get_order_sn(),
- 'pay_no' => get_order_sn(),
- 'goods_num' => array_sum(array_column($goods_data,'num')),
- 'pro_name' => $address['pro_name'],
- 'city_name' =>$address['city_name'],
- 'county_name' => $address['county_name'],
- 'add_detail' => $address['detail'],
- 'phone' => $address['phone'],
- 'sex' => $address['sex'],
- 'user_name' => $address['name'],
- 'remark' => $remark,
- 'images' => $images,
- 'coupon_id' => $coupon_id,
- 'module' => $this->module,
- ];
- $order_item = [];
- array_walk($list,function (&$v)use (&$price_total,$goods_column,&$order_item){
- $item_price = bcmul($v['price'],$goods_column[$v['id']]['num'],2);
- $price_total = bcadd($item_price,$price_total,2);
- $order_item[] = [
- 'user_id' => $this->user_id,
- 'goods_id' => $v['id'],
- 'goods_name' => $v['name'],
- 'cover' => $v['cover'],
- 'sell_price' => $v['price'],
- 'pay_price' => $item_price,
- 'wash_type' => $v['wash_type'],
- 'num' => $goods_column[$v['id']]['num'],
- ];
- });
- array_multisort(array_column($order_item,'sell_price'),SORT_DESC,$order_item);
- $order_info['price_total'] = bcadd($postage,$price_total,2);
- $order_info['postage'] = $postage;
- $order_info = WashOrder::create($order_info)->toArray();
- array_walk($order_item,function (&$v,$k)use ($order_info){
- $v['order_id'] = $order_info['id'];
- });
- (new WashOrderItem())->insertAll($order_item);// 生成订单商品详情
- $ret_data['order_id'] = $order_info['id'];
- if($price_total == 0) OrderCallback::washOrderCallBack($order_info,1);
- Db::commit();
- }catch (\Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- $this->success('ok',$ret_data);
- }
- /**
- * @title 获取订单详情
- * @desc 获取订单详情
- * @author qc
- * @url /api/Wash_manage/getOrderDetail
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:1 desc:订单id
- * @return name:id type:int default:-- desc:订单id
- * @return name:module type:int default:-- desc:1洗鞋2洗衣
- * @return name:order_no type:string default:-- desc:订单号
- * @return name:price_total type:float default:-- desc:待支付金额
- * @return name:price_express type:0 default:-- desc:运费金额
- * @return name:pay_state type:int default:-- desc:支付状态(0未支付1已支付)
- * @return name:pay_type type:int default:-- desc:支付方式(1微信)
- * @return name:pay_no type:string default:-- desc:支付号
- * @return name:pay_at type:string default:-- desc:支付时间
- * @return name:cancel_state type:int default:-- desc:取消状态(0未取消1已取消)
- * @return name:cancel_at type:string default:-- desc:取消时间
- * @return name:cancel_desc type:string default:-- desc:取消原因
- * @return name:status type:int default:-- desc:订单状态(0待支付,1已支付,2待取送,3订单完成,8退款,9取消)
- * @return name:create_at type:string default:-- desc:下单时间
- * @return name:pay_at type:string default:-- desc:支付时间
- * @return name:remark type:string default:-- desc:订单备注
- * @return name:finish_time type:string default:-- desc:完成时间
- * @return name:finish_int type:string default:-- desc:完成时间【时间戳】
- * @return name:images type:string default:-- desc:图片(多张|隔开)
- * @return name:images_arr type:array default:-- desc:图片
- * @return name:goods_num type:int default:-- desc:订单商品总数量
- * @return name:pro_name type:string default:-- desc:省名称(收货地址)
- * @return name:city_name type:string default:-- desc:市名称(收货地址)
- * @return name:county_name type:string default:-- desc:县区名称(收货地址)
- * @return name:add_detail type:string default:-- desc:详细地址(收货地址)
- * @return name:user_name type:string default:-- desc:收货人
- * @return name:phone type:string default:-- desc:收货人联系电话
- * @return name:sex type:int require:1 default:-- desc:性别(1男2女)
- * @return name:second type:int default:-- desc:倒计时(单位秒)
- * @return name:afresh_order type:int default:-- desc:重洗订单id,没申请是0
- * @return name:order_item type:array default:-- desc:订单商品列表
- * @return name:order_item.name type:string default:-- desc:商品名
- * @return name:order_item.cover type:string default:-- desc:商品图
- * @return name:order_item.sell_price type:float default:-- desc:洗涤价格
- * @return name:order_item.num type:int default:-- desc:数量
- * @return name:order_item.wash_type_name type:int default:-- desc:洗涤类型
- */
- public function getOrderDetail()
- {
- $order_id = input('get.id');
- $field = 'id,module,order_no,status,price_total,pay_state,images,pay_no,is_deleted,pay_at,cancel_state,goods_num,remark,pro_name,city_name,county_name,add_detail,user_name,phone,postage,create_at,finish_int,finish_time,sex';
- $detail = WashOrder::field($field)
- ->with('orderItem')->where('id',$order_id)->find()->toArray();
- if($detail['is_deleted'] == 1) $this->error('订单已删除');
- $detail['images_arr'] = $detail['images'] ? explode('|',$detail['images']) : null;
- $afresh_order = AfreshOrder::where('wash_id',$detail['id'])->where('cancel_state',0)->value('id');
- $detail['afresh_order'] =intval($afresh_order);
- $detail['second'] = 0;
- if($detail['status'] == 0) {
- $detail['second'] = time() - strtotime($detail['create_at']) + 900;
- }
- $this->success('ok',['detail'=>$detail]);
- }
- /**
- * @title 获取订单列表
- * @desc 获取订单列表
- * @author qc
- * @method GET
- * @url /api/Wash_manage/getOrderList
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int default:1 desc:页数
- * @param name:page_num type:int default:20 desc:每页数
- * @param name:sel_status type:int default:1 desc:订单类型(0全部1待支付2已支付3待取送4已完成)
- * @return name:order_no type:string default:-- desc:订单号
- * @return name:price_total type:float default:-- desc:待支付金额
- * @return name:price_express type:0 default:-- desc:运费金额
- * @return name:pay_state type:int default:-- desc:支付状态(0未支付1已支付)
- * @return name:pay_type type:int default:-- desc:支付方式(1微信)
- * @return name:pay_no type:string default:-- desc:支付号
- * @return name:pay_at type:string default:-- desc:支付时间
- * @return name:cancel_state type:int default:-- desc:取消状态(0未取消1已取消)
- * @return name:cancel_at type:string default:-- desc:取消时间
- * @return name:cancel_desc type:string default:-- desc:取消原因
- * @return name:status type:int default:-- desc:订单状态(0待支付,1已支付,2待取送,3订单完成,8退款,9取消)
- * @return name:create_at type:string default:-- desc:下单时间
- * @return name:finish_time type:string default:-- desc:完成时间
- * @return name:finish_int type:string default:-- desc:完成时间【时间戳】
- * @return name:pay_at type:string default:-- desc:支付时间
- * @return name:remark type:string default:-- desc:订单备注
- * @return name:goods_num type:int default:-- desc:订单商品总数量
- * @return name:pro_name type:string default:-- desc:省名称(收货地址)
- * @return name:city_name type:string default:-- desc:市名称(收货地址)
- * @return name:county_name type:string default:-- desc:县区名称(收货地址)
- * @return name:add_detail type:string default:-- desc:详细地址(收货地址)
- * @return name:user_name type:string default:-- desc:收货人
- * @return name:sex type:int default:-- desc:性别(1男2女)
- * @return name:phone type:string default:-- desc:收货人联系电话
- * @return name:order_item type:array default:-- desc:订单商品列表
- * @return name:order_item.name type:float default:-- desc:商品名
- * @return name:order_item.cover type:float default:-- desc:商品图
- * @return name:order_item.sell_price type:float default:-- desc:洗涤价格(单件)
- * @return name:order_item.num type:int default:-- desc:数量
- * @return name:order_item.wash_type_name type:int default:-- desc:洗涤类型
- */
- public function getOrderList()
- {
- $sel_status = input('get.sel_status',0);
- $where = [];
- $where[] = ['user_id','=',$this->user_id];
- $where[] = ['is_deleted','=',0];
- $where[] = ['cancel_state','=',0];
- $where[] = ['refund_state','=',0];
- switch ($sel_status)
- {
- case 1:
- $where[] = ['pay_state','=',0];
- break;
- case 2:
- $where[] = ['pay_state','=',1];
- break;
- case 3:
- $where[] = ['status','=','2'];
- break;
- case 4:
- $where[] = ['status','=','3'];
- break;
- }
- $field = 'id,module,order_no,status,price_total,pay_state,pay_no,pay_at,cancel_state,goods_num,remark,pro_name,city_name,county_name,add_detail,user_name,phone,postage,create_at,finish_int,finish_time,sex';
- $list = WashOrder::field($field)->with(['orderItem'])->where($where)->order('id desc ')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 订单支付
- * @desc 订单支付
- * @author qc
- * @url /api/Wash_manage/payOrder
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int require:1 default:0 desc:订单id
- * @return name:config type:array default:0 desc:小程序支付配置
- * @return name:config.appId type:string default:-- desc:appid
- * @return name:config.nonceStr type:string default:-- desc:随机字符串
- * @return name:config.signType type:string default:-- desc:签名类型
- * @return name:config.paySign type:string default:-- desc:签名
- * @return name:config.timestamp type:string default:-- desc:时间戳
- */
- public function payOrder()
- {
- $order_id = input('post.id');
- $field = 'id,module,status,order_no,price_total,pay_state,pay_no,is_deleted,pay_at,cancel_state,goods_num,remark,pro_name,city_name,county_name,add_detail,user_name,phone,postage';
- $order_info = WashOrder::field($field)
- ->with('orderItem')->where('id',$order_id)->find()->toArray();
- if($order_info['is_deleted'] == 1) $this->error('订单已删除');
- if($order_info['cancel_state'] == 1) $this->error('订单已取消');
- if($order_info['status'] != 0) $this->error('订单已支付');
- $user_info = $this->userInfo();
- $ret_data = ['pay_status'=>0,'config'=>[]];
- $notify_url = $this->request->root(true) . '/api/we_chat_pay/washOrderNotify';
- $config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['price_total'],$notify_url,'JSAPI',$user_info['openid']);
- if(!$config) $this->error('支付配置错误');
- $ret_data['config']=$config['config'];
- $this->success('ok',$ret_data);
- }
- /**
- * @title 取消订单
- * @desc 取消订单
- * @author qc
- * @url /api/Wash_manage/cancelOrder
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int require:1 default:0 desc:订单id
- */
- public function cancelOrder()
- {
- $order_id = input('post.id');
- $field = 'id,module,status,order_no,price_total,pay_state,pay_no,is_deleted,pay_at,cancel_state,goods_num,remark,pro_name,city_name,county_name,add_detail,user_name,phone,postage';
- $order_info = WashOrder::field($field)
- ->with('orderItem')->where('id',$order_id)->find()->toArray();
- if($order_info['is_deleted'] == 1) $this->error('订单已删除');
- if($order_info['cancel_state'] == 1) $this->error('订单已取消');
- if($order_info['status'] == 8) $this->error('订单已取消');
- if($order_info['status'] == 0){
- WashOrder::where('id',$order_id)->update(['status'=>9,'cancel_state'=>1,'cancel_at'=>date('Y-m-d H:i:s')]);
- }else{
- $refund_info = [
- 'user_id' => $this->user_id ,
- 'order_id' => $order_id ,
- 'num' => $order_info['goods_num'],
- 'apply_case' => '订单取消',
- 'is_deleted'=> 0,
- 'refund_type'=> 1,
- 'create_at'=> date('Y-m-d H:i:s'),
- 'refund_no'=> 'W'.$order_info['order_no'],
- 'source'=> 2,
- 'refund_money'=>$order_info['price_total'],
- ];
- $res = \library\tools\Data::save('StoreOrderRefund',$refund_info,'order_id',['order_id'=>$order_id,'source'=>2]);
- $refund_info =StoreOrderRefund::where(['order_id'=>$order_id,'source'=>2,'user_id'=>$this->user_id])->find()->toArray();
- WashOrder::where(['id'=>$order_id])->update(['refund_state'=>1]);
- OrderCallback::refundMoney($refund_info ,$order_info,$order_id);
- }
- $this->success('订单取消成功');
- }
- /**
- * @title 以下接口为重洗订单接口
- * @desc 以下接口为重洗订单接口
- * @author qc
- * @url /api/Wash_manage/classIntro
- * @method GET
- * @return name:1 type:string default:-- desc:重洗申请页面的商品可以调用订单详情接口获取商品列表
- */
- public function classIntro(){}
- /**
- * @title 申请重洗
- * @desc 申请重洗
- * @author qc
- * @url /api/Wash_manage/applyAfreshOrder
- * @method POST
- * @param name:order_id type:int require:1 default:0 desc:洗涤订单id
- * @param name:goods_json type:string require:1 default:0 desc:商品json信息[{'item_id':'订单的商品列表id','num':'数量'}]
- * @param name:images type:string require:0 default:0 desc:图片(多张|隔开)
- */
- public function applyAfreshOrder()
- {
- $order_id = input('post.order_id','');
- $goods_json = input('post.goods_json','');
- $remark = input('post.remark','');
- $images = input('post.images','');
- $goods_data = json_decode($goods_json,true);
- $wash_order = WashOrder::where('id',$order_id)->find()->toArray();
- $check = AfreshOrder::where('wash_id',$order_id)
- ->where('is_deleted',0)->where('cancel_state',0)
- ->value('id');
- if($check) $this->error('已申请重洗');
- if($wash_order['status'] !=3) $this->error('订单未完成');
- if($wash_order['finish_int'] < time() - 86400 * 2) $this->error('订单已完成48小时,无法申请重洗');
- Db::startTrans();
- try {
- $order_info = [
- 'user_id' => $this->user_id,
- 'wash_id' => $order_id,
- 'order_no' => get_order_sn(),
- 'goods_num' => array_sum(array_column($goods_data,'num')),
- 'remark' => $remark,
- 'images' => $images,
- 'module' => $wash_order['module'],
- ];
- $order_info = AfreshOrder::create($order_info);
- $item= [] ;
- foreach ($goods_data as $iv) {
- $check_item = WashOrderItem::where('id',$iv['item_id'])->value('num');
- if($iv['num'] > $check_item) $this->exception('重洗数量错误');
- $item[]= [
- 'user_id' => $this->user_id,
- 'afresh_id' => $order_info['id'],
- 'item_id' => $iv['item_id'],
- 'num' => $iv['num'],
- ];
- }
- (new AfreshOrderItem())->insertAll($item);
- Db::commit();
- }catch (\Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- $this->success('申请成功等待审核');
- }
- /**
- * @title 申请重洗订单列表
- * @desc 申请重洗订单列表
- * @author qc
- * @url /api/Wash_manage/getAfreshOrderList
- * @method GET
- * @param name:page type:int default:1 desc:页数
- * @param name:page_num type:int default:20 desc:每页数
- * @return name:id type:int require:1 default:0 desc:重洗订单id
- * @return name:status type:int require:1 default:0 desc:订单状态(0默认状态【未处理】1待取送2订单完成)
- * @return name:sh_status type:int require:1 default:0 desc:审核状态(0待审核1审核通过2审核拒绝)
- * @return name:sh_remark type:string require:1 default:0 desc:审核备注
- * @return name:wash_id type:int require:1 default:0 desc:洗涤订单id
- * @return name:pro_name type:string default:-- desc:省名称(收货地址)
- * @return name:city_name type:string default:-- desc:市名称(收货地址)
- * @return name:county_name type:string default:-- desc:县区名称(收货地址)
- * @return name:add_detail type:string default:-- desc:详细地址(收货地址)
- * @return name:add_detail type:int default:-- desc:清洗数量
- * @return name:user_name type:string default:-- desc:收货人
- * @return name:phone type:string default:-- desc:收货人联系电话
- * @return name:sex type:int require:1 default:-- desc:性别(1男2女)
- * @return name:order_item type:array default:-- desc:订单商品列表
- * @return name:order_item.name type:string default:-- desc:商品名
- * @return name:order_item.cover type:string default:-- desc:商品图
- * @return name:order_item.sell_price type:float default:-- desc:洗涤价格
- * @return name:order_item.num type:int default:-- desc:清洗数量
- */
- public function getAfreshOrderList()
- {
- $list = AfreshOrder::field('a.id,a.wash_id,a.status,a.images,pro_name,city_name,county_name,add_detail,user_name,phone,a.module,sh_status,w.sex')
- ->alias('a')
- ->with('orderItem')
- ->leftJoin('WashOrder w','w.id = a.wash_id')
- ->where('a.user_id',$this->user_id)
- ->where('a.cancel_state',0)
- ->order('a.id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- array_walk($list,function (&$v){
- $v['images_arr'] = $v['images'] ? explode("|",$v['images']) : null;
- });
- $this->success('ok',['detail'=>$list]);
- }
- /**
- * @title 获取申请重洗订单详情
- * @desc 获取申请重洗订单详情
- * @author qc
- * @url /api/Wash_manage/applyAfreshOrderDetail
- * @method GET
- * @param name:order_id type:int require:1 default:0 desc:洗涤订单id
- * @return name:id type:int require:1 default:0 desc:重洗订单id
- * @return name:status type:int require:1 default:0 desc:订单状态(0默认状态【未处理】1待取送2订单完成)
- * @return name:sh_status type:int require:1 default:0 desc:审核状态(0待审核1审核通过2审核拒绝)
- * @return name:sh_remark type:string require:1 default:0 desc:审核备注
- * @return name:wash_id type:int require:1 default:0 desc:洗涤订单id
- * @return name:pro_name type:string default:-- desc:省名称(收货地址)
- * @return name:city_name type:string default:-- desc:市名称(收货地址)
- * @return name:county_name type:string default:-- desc:县区名称(收货地址)
- * @return name:add_detail type:string default:-- desc:详细地址(收货地址)
- * @return name:add_detail type:int default:-- desc:清洗数量
- * @return name:user_name type:string default:-- desc:收货人
- * @return name:phone type:string default:-- desc:收货人联系电话
- * @return name:sex type:int default:-- desc:性别(1男2女)
- * @return name:order_item type:array default:-- desc:订单商品列表
- * @return name:order_item.name type:string default:-- desc:商品名
- * @return name:order_item.cover type:string default:-- desc:商品图
- * @return name:order_item.sell_price type:float default:-- desc:洗涤价格
- * @return name:order_item.num type:int default:-- desc:清洗数量
- */
- public function applyAfreshOrderDetail()
- {
- $order_id = input('get.order_id');
- $detail = AfreshOrder::field('a.id,a.wash_id,a.status,a.sh_remark,a.images,pro_name,city_name,county_name,add_detail,user_name,phone,a.module,sh_status,w.sex')
- ->alias('a')
- ->with('orderItem')
- ->leftJoin('WashOrder w','w.id = a.wash_id')
- ->where('w.id',$order_id)
- ->where('a.cancel_state',0)
- ->find();
- if(!$detail) $this->error('订单暂未申请重洗');
- $detail= $detail->toArray();
- $detail['images_arr'] = $detail['images'] ? explode("|",$detail['images']) : null;
- $this->success('ok',['detail'=>$detail]);
- }
- /**
- * @title 取消重洗
- * @desc 取消重洗
- * @author qc
- * @url /api/Wash_manage/cancelAfreshOrder
- * @method POST
- * @param name:id type:int require:1 default:0 desc:重洗订单id
- */
- public function cancelAfreshOrder()
- {
- AfreshOrder::where('id',input('post.id'))
- ->where('user_id',$this->user_id)
- ->update(['cancel_state'=>1]);
- $this->success('取消成功');
- }
- }
|