auth->group_id != 3){$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'); }, /*'extend' => function ($query) { $query->field('id,order_id,address_id,address_json,express_number,express_company'); }, 'evaluate' => function ($query) { $query->field('id,order_id,product_id'); }*/ ]) ->where(['id' => $order_id])->find(); if ($order) { $order = $order->append(['state', 'paidtime'])->toArray(); // 快递单号 /*$order['express_number'] = $order['extend']['express_number']; $order['express_company'] = '快递单号'; $order['express'] = ''; if (class_exists(\addons\expressquery\library\Expressquery::class)) { $expressInfo = Db::name('expressquery')->where(['express' => $order['extend']['express_company']])->find(); $order['express_company'] = $expressInfo['name'] ?? '快递单号'; $order['express'] = $expressInfo['express'] ?? ''; }*/ // 送货地址 /*$address = json_decode($order['extend']['address_json'], true); $area = (new \addons\unishop\model\Area()) ->whereIn('id', [$address['province_id'], $address['city_id'], $address['area_id']]) ->column('name', 'id'); $delivery['username'] = $address['name']; $delivery['mobile'] = $address['mobile']; $delivery['address'] = $area[$address['province_id']] . ' ' . $area[$address['city_id']] . ' ' . $area[$address['area_id']] . ' ' . $address['address']; $order['delivery'] = $delivery;*/ // 是否已评论 // $evaluate = array_column($order['evaluate'], 'product_id'); foreach ($order['products'] as &$product) { $product['image'] = cdnurl($product['image']); /*if (in_array($product['id'], $evaluate)) { $product['evaluate'] = true; } else { $product['evaluate'] = false; }*/ //限定核销产品 if(!in_array($product['product_id'],explode(',',$this->auth->product_ids))){ $this->error('您无法核销当前订单,请移至正确核销点,或联系客服','',2); } } // unset($order['evaluate']); unset($order['extend']); 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->group_id != 3){$this->error('你是不是来错地方了?');} // $order_id = input('order_id', 0); // $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id); $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('该订单已核销'); } //限定核销产品 $products = Db::name('unishop_order_product')->where('order_id',$order['id'])->select(); foreach($products as $key => $product){ if(!in_array($product['product_id'],explode(',',$this->auth->product_ids))){ $this->success('您无法核销当前订单,请移至正确核销点,或联系客服','',2); } } $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('核销失败'); } //给推广人结算 if($order['intro_uid']){ $bili = config('site.unishop_order_intromoney_bili'); $money = bcdiv(bcmul($order['total_price'],$bili,2),100,2); if($money > 0){ $rs_wallet = model('Wallet')->lockChangeAccountRemain($order['intro_uid'],'money',$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); } }