| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- <?php
- /**
- * @package merchant
- *
- * @author Qinii
- * @day 2020-06-15
- *
- *
- */
- namespace app\controller\admin\order;
- use app\common\repositories\user\UserRepository;
- use app\services\ThirdParty\AlibabaAgent\OrderService;
- use crmeb\basic\BaseController;
- use app\common\repositories\store\order\MerchantReconciliationorderRepository;
- use app\common\repositories\store\order\MerchantReconciliationRepository;
- use app\common\repositories\system\merchant\MerchantRepository;
- use app\common\repositories\store\order\StoreRefundOrderRepository as repository;
- use think\App;
- use think\facade\Db;
- class RefundOrder extends BaseController
- {
- protected $repository;
- public function __construct(App $app,repository $repository)
- {
- parent::__construct($app);
- $this->repository = $repository;
- }
- public function lst($id)
- {
- [$page,$limit] = $this->getPage();
- // $where['reconciliation_type'] = $this->request->param('status',1);
- $where['status'] =$this->request->param('status','');
- $where['date'] = $this->request->param('date');
- $where['mer_id'] = $id;
- $where['status'] = 3;
- return app('json')->success($this->repository->getAdminList($where,$page,$limit));
- }
- public function markForm($id)
- {
- if(!$this->repository->getWhereCount([$this->repository->getPk() => $id]))
- return app('json')->fail('数据不存在');
- return app('json')->success(formToData($this->repository->adminMarkForm($id)));
- }
- public function mark($id)
- {
- if(!$this->repository->getWhereCount([$this->repository->getPk() => $id]))
- return app('json')->fail('数据不存在');
- $data = $this->request->params(['admin_mark']);
- $this->repository->update($id,$data);
- return app('json')->success('备注成功');
- }
- public function getAllList()
- {
- [$page,$limit] = $this->getPage();
- $where = $this->request->params(['refund_order_sn','status','refund_type','date','mer_id','order_sn']);
- return app('json')->success($this->repository->getAllList($where, $page, $limit));
- }
- /**
- * @return mixed
- * @author 史晨
- * @date 2026/5/8 17:27
- * 1688订单获取退款原因
- */
- public function refundReasonList()
- {
- $orderId = request()->param('alibaba_order_id');
- if (empty($orderId)) {
- return app('json')->fail('订单号不能为空');
- }
- $orderService = new OrderService();
- $params = ['orderId' => $orderId];
- $result = $orderService->getRefundReasonList($params);
- if ($result === false) {
- return app('json')->fail('获取退款原因失败');
- }
- return app('json')->success($result);
- }
- public function detail($id)
- {
- $data=$this->repository->getOne($id);
- return app('json')->success($data);
- }
- /**
- * @param $id
- * @return mixed
- * @author Qinii
- * @day 2020-06-12
- */
- public function switchStatus($id)
- {
- $status=-1;
- if($this->request->param('status') == 1){
- $status=1;
- }else if($this->request->param('status') == 2){
- $status=2;
- }
- // $status = ($this->request->param('status') == 1) ? 1 : -1;
- if($status == 1 || $status == 2){
- $refund_order=$this->repository->get($id);
- if($status==2){
- $part_refund_message = $this->request->param('part_refund_message','');
- $refund_price =(float) $this->request->param('part_refund_price',0);
- if($refund_price<0.01){
- return app('json')->fail('退款金额不能小于0.01');
- }
- if($refund_order && $refund_price >$refund_order['refund_price']){
- return app('json')->fail('退款金额不能大于用户申请金额');
- }
- if($part_refund_message==''){
- return app('json')->fail('请填写商家备注');
- }
- $this->repository->update($id,['part_refund_price'=>$refund_price,'part_refund_message' => $part_refund_message,'part_refund_time'=>date('Y-m-d H:i:s')]);
- }
- $douduo = $this -> repository -> douduofund($id,true);
- if($douduo['code'] < 0){
- return app('json')->fail($douduo['message']);
- }
- if($douduo['code'] == 2){
- return app('json')->success($douduo['message']);
- }
- $data = $this->request->params(['mer_delivery_user','mer_delivery_address','phone']);
- if($refund_order['refund_type']==2 && $status == 1 && ($data['mer_delivery_user']=='' || $data['mer_delivery_address']=='' || $data['phone']=='')){
- return app('json')->fail('请输入收货人信息');
- }
- $data['status'] = $status;
- // Db::name('log')->insert(['data'=>'这了'. 1]);
- $this->repository->agree($id,$data,$this->request->adminId(),1);
- // 获取订单金额
- $store_order_info = Db::name('store_order')
- ->where('order_id', $refund_order['order_id'])
- ->find();
- $group_order_map = Db::name('store_group_order')
- ->where('group_order_id', $store_order_info['group_order_id'])
- ->field('uid,pay_price,hf_pay_id,fzone_paytype')
- ->find();
- $make = '商贸区';
- if ($store_order_info['mer_id'] == 439) {
- $make = '精彩生活区';
- } else if ($store_order_info['mer_id'] == 496) {
- $make = '会员专区';
- } else if ($store_order_info['mer_id'] == 491) {
- $make = '复购区';
- }
- // 如果是组合支付 现金 + 积分 则需要把积分退回
- // 参考 app\controller\api\Notify.php -- 745 $array_fzone_paytype['type']=='b2'
- $array_fzone_paytype = json_decode($group_order_map['fzone_paytype'], true);
- if (!empty($array_fzone_paytype)) {
- if ($array_fzone_paytype['type'] == 'b1') {
- // VR+积分 {"checked":true,"note":"VR+积分","other":210.0,"price":970.0,"total":0.0,"type":"b1","vr":"47557.5"}
- $vrpri = Db::name("user")->where("uid", $group_order_map['uid'])->value('vr');
- $vrpri += $array_fzone_paytype['price'];
- Db::name("user")->where("uid", $group_order_map['uid'])->update(['vr' => $vrpri]);
- Db::name("user_sign_vr")->insert([
- 'uid' => $store_order_info['uid'],
- 'number' => $array_fzone_paytype['price'],
- 'mark' => "{$make}商品申请退款退回VR",
- 'desc' => "VR",
- 'order_type' => 0,
- 'order_id' => $store_order_info['order_id'],
- 'surplus' => $vrpri,
- 'type' => 1,
- 'addtime' => time()
- ]);
- // {"checked":true,"note":"VR+积分","other":1.5,"price":8.5,"total":0.0,"type":"b2","vr":"48799.82"}
- $vrpri = Db::name("user")->where("uid", $group_order_map['uid'])->value('score');
- $vrpri += $array_fzone_paytype['other'];
- Db::name("user")->where("uid", $group_order_map['uid'])->update(['score' => $vrpri]);
- $data = [
- "uid" => $store_order_info['uid'],
- "reward_socre" => $array_fzone_paytype['other'],
- "addtime" => time(),
- "status" => 1,
- "order_id" => $store_order_info['order_id'],
- "mark" => "{$make}商品申请退款退回积分",
- "surplus" => $vrpri,
- "pm" => 1,
- "source_type" => 3
- ];
- Db::name("user_sign_score")->insert($data);//添加积分记录
- } else if ($array_fzone_paytype['type'] == 'b2') {
- // {"checked":true,"note":"现金+积分","other":1.5,"price":8.5,"total":0.0,"type":"b2","vr":"48799.82"}
- $vrpri = Db::name("user")->where("uid", $group_order_map['uid'])->value('score');
- $vrpri += $array_fzone_paytype['other'];
- Db::name("user")->where("uid", $group_order_map['uid'])->update(['score' => $vrpri]);
- $data = [
- "uid" => $store_order_info['uid'],
- "reward_socre" => $array_fzone_paytype['other'],
- "addtime" => time(),
- "status" => 1,
- "order_id" => $store_order_info['order_id'],
- "mark" => "{$make}商品申请退款退回积分",
- "surplus" => $vrpri,
- "pm" => 1,
- "source_type" => 3
- ];
- Db::name("user_sign_score")->insert($data);//添加积分记录
- } else if ($array_fzone_paytype['type'] == 'b3') {
- // VR+积分 {"checked":true,"note":"VR+积分","other":210.0,"price":970.0,"total":0.0,"type":"b1","vr":"47557.5"}
- $vrpri = Db::name("user")->where("uid", $group_order_map['uid'])->value('vr');
- $vrpri += $array_fzone_paytype['price'];
- Db::name("user")->where("uid", $group_order_map['uid'])->update(['vr' => $vrpri]);
- Db::name("user_sign_vr")->insert([
- 'uid' => $store_order_info['uid'],
- 'number' => $array_fzone_paytype['price'],
- 'mark' => "{$make}商品申请退款退回VR",
- 'desc' => "VR",
- 'order_type' => 0,
- 'order_id' => $store_order_info['order_id'],
- 'surplus' => $vrpri,
- 'type' => 1,
- 'addtime' => time()
- ]);
- // {"checked":true,"note":"VR+积分","other":1.5,"price":8.5,"total":0.0,"type":"b2","vr":"48799.82"}
- $vrpri = Db::name("user")->where("uid", $group_order_map['uid'])->value('jingdou');
- $vrpri += $array_fzone_paytype['other'];
- Db::name("user")->where("uid", $group_order_map['uid'])->update(['jingdou' => $vrpri]);
- Db::name('user_sign_jingdou')->insert([
- 'uid' => $store_order_info['uid'],
- 'number' => $array_fzone_paytype['other'],
- 'status' => 1,
- 'mark' => "{$make}商品申请退款退回京豆",
- 'addtime' => time(),
- 'surplus' => $vrpri,
- 'settlement_time' => date('Y-m-d H:i:s'),
- 'type' => 1,
- 'order_type' => 0,
- 'order_id' => $store_order_info['order_id']
- ]);
- } else if ($array_fzone_paytype['type'] == 'b4') {
- // {"checked":true,"note":"现金+积分","other":1.5,"price":8.5,"total":0.0,"type":"b2","vr":"48799.82"}
- $jingdoupri = Db::name("user")->where("uid", $group_order_map['uid'])->value('jingdou');
- $jingdoupri += $array_fzone_paytype['other'];
- Db::name("user")->where("uid", $group_order_map['uid'])->update(['jingdou' => $jingdoupri]);
- Db::name('user_sign_jingdou')->insert([
- 'uid' => $store_order_info['uid'],
- 'number' => $array_fzone_paytype['other'],
- 'status' => 1,
- 'mark' => "{$make}商品申请退款退回京豆",
- 'addtime' => time(),
- 'surplus' => $jingdoupri,
- 'settlement_time' => date('Y-m-d H:i:s'),
- 'type' => 1,
- 'order_type' => 0,
- 'order_id' => $store_order_info['order_id']
- ]);
- } else if ($array_fzone_paytype['type'] == 'b5') {
- // {"checked":true,"note":"VR","other":0.0,"price":1.0,"total":0.0,"type":"b5","vr":"10"}
- $vrpri = Db::name("user")->where("uid", $group_order_map['uid'])->value('vr');
- $vrpri += $array_fzone_paytype['price'];
- Db::name("user")->where("uid", $group_order_map['uid'])->update(['vr' => $vrpri]);
- Db::name("user_sign_vr")->insert([
- 'uid' => $store_order_info['uid'],
- 'number' => $array_fzone_paytype['price'],
- 'mark' => "{$make}商品申请退款退回VR",
- 'desc' => "VR",
- 'order_type' => 0,
- 'order_id' => $store_order_info['order_id'],
- 'surplus' => $vrpri,
- 'type' => 1,
- 'addtime' => time()
- ]);
- } else if ($array_fzone_paytype['type'] == 'a3') {
- // {"checked":true,"note":"现金+VR","other":1.5,"price":8.5,"total":0.0,"type":"a3","vr":"48799.82"}
- $vrpri = Db::name("user")->where("uid", $group_order_map['uid'])->value('vr');
- $vrpri += $array_fzone_paytype['other'];
- Db::name("user")->where("uid", $group_order_map['uid'])->update(['vr' => $vrpri]);
- //VR入账
- $insertdata = [
- 'uid'=> $store_order_info['uid'],
- 'number' => $array_fzone_paytype['other'],
- 'surplus' => $vrpri,
- 'mark' => "{$make}商品申请退款退回VR",
- 'order_id'=> $store_order_info['order_id'],
- 'type' => 2,
- 'addtime' => time(),
- 'settlement_time'=> date('Y-m-d H:i:s', time())
- ];
- Db::name('user_sign_vr')->insert($insertdata);
- } else if ($array_fzone_paytype['type'] == 'c1') {
- // {"checked":true,"note":"复购金","other":1.5,"price":8.5,"total":0.0,"type":"c1","vr":"48799.82"}
- $vrpri = Db::name("user")->where("uid", $group_order_map['uid'])->value('fugou');
- $vrpri += $array_fzone_paytype['price'];
- Db::name("user")->where("uid", $group_order_map['uid'])->update(['fugou' => $vrpri]);
- //支出账号存到log日志
- $log_data = [
- 'uid' => $store_order_info['uid'],
- 'number' => $array_fzone_paytype['price'],
- 'mark' => "复购区商品申请退款退回复购金:" . $array_fzone_paytype['price'],
- 'desc' => "复购金",
- 'order_id' => $store_order_info['order_id'],
- 'surplus' => $vrpri,
- 'order_type' => 0,
- 'type' => 1,
- 'addtime' => time()
- ];
- Db::name("user_sign_fugou")->insert($log_data);
- }
- }
- // 取消 订单所发放的福利
- $this->repository->cancelOrderBonus($id);
- }else{
- $fail_message = $this->request->param('fail_message','');
- if($status == -1 && empty($fail_message)){
- return app('json')->fail('未通过必须填写');
- }
- if($fail_message==''){
- return app('json')->fail('未通过必须填写');
- }
- $data['status'] = $status;
- $data['fail_message'] = $fail_message;
- $this->repository->refuse($id,$data);
- $this->repository->set_consult(2,$id);//协商记录
- }
- return app('json')->success('审核成功');
- }
- /**
- * TODO 收货后确定退款
- * @param $id
- * @return mixed
- * @author Qinii
- * @day 2020-06-12
- */
- public function refundPrice($id)
- {
- if($this->request->param('status') == 2){
- $part_refund_message = $this->request->param('part_refund_message','');
- $refund_price =(float) $this->request->param('part_refund_price',0);
- if($refund_price<0.01){
- return app('json')->fail('退款金额不能小于0.01');
- }
- $refund_order=$this->repository->get($id);
- if($refund_order && $refund_price>$refund_order['refund_price']){
- return app('json')->fail('退款金额不能大于用户申请金额');
- }
- $this->repository->update($id,['part_refund_price'=>$refund_price,'part_refund_message' => $part_refund_message,'part_refund_time'=>date('Y-m-d H:i:s')]);
- }else if($this->request->param('status') == -1){
- $fail_message = $this->request->param('fail_message','');
- if(empty($fail_message))
- return app('json')->fail('未通过必须填写');
- $data['status'] = -1;
- $data['fail_message'] = $fail_message;
- $this->repository->refuse($id,$data);
- $this->repository->set_consult(7,$id);//协商记录
- return app('json')->success('拒绝成功');
- }
- $this->repository->set_consult(5,$id);//协商记录
- $this->repository->adminRefund($id,$this->request->adminId());
- return app('json')->success('退款成功');
- }
- /**
- * TODO 快递查询
- * @param $id
- * @return mixed
- * @author Qinii
- * @day 2020-06-25
- */
- public function express($id)
- {
- // if(!$this->repository->getWhereCount(['refund_order_id' => $id,'status' =>2]))
- // return app('json')->fail('订单信息或状态错误');
- return app('json')->success($this->repository->express($id));
- }
- public function reList($id)
- {
- [$page,$limit] = $this->getPage();
- $where = ['reconciliation_id' => $id,'type' => 1];
- return app('json')->success($this->repository->reconList($where,$page,$limit));
- }
- public function dhm_list(){
- [$page,$limit] = $this->getPage();
- $status = $this->request->param('status','');
- $order_sn = $this->request->param('order_sn');
- $refund_order_sn = $this->request->param('refund_order_sn');
- $query = Db::name('StoreRefundOrder')
- -> alias('sro')
- -> join('StoreOrder so','sro.order_id = so.order_id')
- -> where('so.supply_type','in',[1,4,5]);
- if($status != ''){
- $query -> where('so.douhuomall_status',$status);
- }
- if($order_sn != ''){
- $query -> where('so.order_sn',$order_sn);
- }
- if($refund_order_sn != ''){
- $query -> where('sro.refund_order_sn',$refund_order_sn);
- }
- $query -> order('sro.refund_order_id desc');
- $count = $query->count();
- $list = $query->page($page, $limit)->field("so.*,sro.*,sro.status as sro_status") -> select();
- if ($list){
- $list = $list -> toArray();
- foreach ($list as $key => &$value){
- $product = Db::name('store_refund_product') -> where('refund_order_id',$value['refund_order_id']) -> select()->each(function ($item){
- $item['product'] = Db::name('store_order_product') -> where('order_product_id',$item['order_product_id']) -> find();
- $item['product']['cart_info'] = json_decode($item['product']['cart_info']);
- return $item;
- });
- $value['refundProduct'] = $product;
- $value['user'] = Db::name('user') -> where('uid',$value['uid']) -> field('nickname,phone,uid') -> find();
- }
- }
- return app('json')->success(compact('count', 'list'));
- }
- public function dhm_status(){
- $status = $this->request->param('status',0);
- $id = $this->request->param('id',0);
- $c = Db::name('StoreRefundOrder') -> where(['refund_order_id' => $id]) -> field('status') -> find();
- if($c['status'] != 0 || !$c || $status == 0) return app('json')->fail('信息或状态错误');
- if ($status == -1){
- $fail_message = $this->request->param('fail_message','');
- if($status == -1 && empty($fail_message))
- return app('json')->fail('未通过必须填写');
- $data['status'] = $status;
- $data['fail_message'] = $fail_message;
- $this->repository->refuse($id,$data);
- }elseif ($status == 2){
- //处理中
- $dhm_msg = $this->request->param('dhm_msg','');
- Db::name('StoreRefundOrder') -> where(['refund_order_id' => $id]) -> update(['dhm_msg'=>$dhm_msg]);
- return app('json')->success('提交成功');
- }else{
- $data['status'] = $status;
- $this->repository->agree($id,$data,$this->request->adminId(),1);
- }
- return app('json')->success('审核成功');
- }
- }
|