auth->is_hexiao != 1){$this->error('没有核销权限');} $code = input('code',''); if(strpos($code,'order_hexiao_no|') !== 0){ $this->error('识别不到的订单'); } $order_no = substr($code,16); $order_info = Db::name('unishop_order')->where('out_trade_no',$order_no)->find(); if(empty($order_info)){ $this->error('不存在的订单'); } if($order_info['status'] != 1){ $this->error('非正常的订单'); } if($order_info['have_paid'] == 0){ $this->error('未支付的订单'); } if($order_info['have_received'] != 0){ $this->error('该订单已核销'); } //下面是从unishop/order.php detail方法里拿过来的 $order_id = $order_info['id']; $orderModel = new \addons\unishop\model\Order(); $order = $orderModel ->with([ 'products' => function ($query) { $query->field('id,order_id,image,number,price,spec,title,product_id'); }, ]) ->where(['id' => $order_id])->find(); if ($order) { $order = $order->append(['state', 'paidtime'])->toArray(); foreach ($order['products'] as &$product) { $product['image'] = cdnurl($product['image']); } unset($order['pay_out_trade_no']); //预约日期 $week_data = [ 0 => '周日', 1 => '周一', 2 => '周二', 3 => '周三', 4 => '周四', 5 => '周五', 6 => '周六', 7 => '周日', ]; $order['bookdate'] = date('Y-m-d H:i',$order['booktime']) .' '. $week_data[date('w',$order['booktime'])]; //追加退改规则 $order['order_refund_rule'] = config('site.order_refund_rule'); //电子凭证,核销码 /*$qrcode_string = 'order_hexiao_no|' . $order['out_trade_no']; $order['order_hexiao_qrcode'] = httpurllocal($this->inviteimage($qrcode_string));*/ } //追加退改规则 $this->success(1,$order); } //完成核销动作 public function hexiao(){ if($this->auth->is_hexiao != 1){$this->error('没有核销权限');} $code = input('code',''); if(strpos($code,'order_hexiao_no|') !== 0){ $this->error('识别不到的订单'); } $out_trade_no = substr($code,16); Db::startTrans(); $order = Db::name('unishop_order')->where(['out_trade_no' => $out_trade_no])->lock(true)->find(); if (!$order) { Db::rollback(); $this->error('不存在的订单'); } if($order['status'] != 1){ Db::rollback(); $this->error('非正常的订单'); } if($order['have_paid'] == 0){ Db::rollback(); $this->error('未支付的订单'); } if($order['have_received'] != 0){ Db::rollback(); $this->error('该订单已核销'); } $update = [ 'have_received' => time(), 'hexiao_uid' => $this->auth->id, ]; $order_rs = Db::name('unishop_order')->where('id',$order['id'])->update($update); if($order_rs === false){ Db::rollback(); $this->error('核销失败'); } //给核销人结算 $bili = config('site.unishop_order_hexiaomoney_bili'); $money = bcdiv(bcmul($order['total_price'],$bili,2),100,2); if($money > 0){ $rs_wallet = model('Wallet')->lockChangeAccountRemain($this->auth->id,'hexiaomoney',$money,10,'核销订单:'.$out_trade_no,'unishop_order',$order['id']); if($rs_wallet['status']===false) { Db::rollback(); $this->error($rs_wallet['msg']); } } Db::commit(); $this->success('核销成功'); } //核销记录 public function order_list(){ if($this->auth->group_id != 3){$this->error('你是不是来错地方了?');} $orderModel = new \addons\unishop\model\Order(); $condition = [ 'hexiao_uid' => $this->auth->id, 'status' => 1, 'have_paid' => ['gt',0], 'have_delivered' => ['gt',0], 'have_received' => ['gt',0], ]; $result = $orderModel ->with([ 'products' => function($query) { $query->field('id,title,image,number,price,spec,order_id,product_id'); }, ]) ->where($condition) ->order(['have_received' => 'desc']) ->autopage() ->select(); //预约日期 $week_data = [ 0 => '周日', 1 => '周一', 2 => '周二', 3 => '周三', 4 => '周四', 5 => '周五', 6 => '周六', 7 => '周日', ]; foreach ($result as &$item) { $item->append(['order_id','state']); $item = $item->toArray(); unset($item['pay_out_trade_no']); /*$evaluate = array_column($item['evaluate'], 'product_id'); $refundProducts = array_column($item['refund_products'], 'order_product_id'); unset($item['evaluate']); unset($item['refund_products']);*/ foreach ($item['products'] as &$product) { $product['image'] = cdnurl($product['image']); // 是否已评论 /*if (in_array($product['id'], $evaluate)) { $product['evaluate'] = true; } else { $product['evaluate'] = false; }*/ // 是否退货 /*if ($item['refund_status'] == self::REFUND_STATUS_AGREE && in_array($product['order_product_id'], $refundProducts)) { $product['refund'] = true; } else { $product['refund'] = false; }*/ } $item['bookdate'] = date('Y-m-d H:i',$item['booktime']) .' '. $week_data[date('w',$item['booktime'])]; } $this->success(1,$result); } }