domain = (new OptionSetting)->getCloudDomainName(); } /** * @return array the validation rules. */ public function rules() { return [ [['certificate', 'id_card_reverse','id_card_front','logo','pic_url','g_s_pic_url', 'reason', 'ids'], 'string', 'max' => 255], [['name', 'password','g_unit','account','bank_name','start_time','end_time','express_name','express_no', 'user_name', 'goods_name', 'sorting_start_time', 'sorting_end_time'], 'string', 'max'=> 255], [['tel','price','g_price','g_original_price', 'g_wholesale_price', 'g_shop_count', 'weight', 'g_wholesale_rebate_switch', 'salesman_id', 'sort', 'market_price', 'pay_price', 'express_price', 'underlined_price'], 'number'], [['cash_type','type','page','limit','supplier_id','could_mch_id','could_user_id','status','g_send_type','attr_id','num','send_type', 'send_type_num', 'centralize_goods_type','cancel_type', 'use_attr', 'is_agree', 'order_type', 'is_purchase', 'id', 'goods_area_rules_id', 'export', 'is_level', 'wholesale_ladder_type', 'goods_full_give_switch'],'integer'], [['goods_no','order_no' ,'desc', 'mobile', 'detail', 'zipcode', 'cat_id', 'g_wholesale_ladder_rebate','order_id','goods_id', 'fields', 'search', 'xlsx', 'goods_full_give_info'],'string'], [['attrs', 'g_pic_list', 'token_supplier_id', 'words', 'address_data', 'seller_comments', 'is_need_install', 'is_default', 'freight', 'purchase_order_id', 'mch_order_no', 'old_order_no', 'zip_code'], 'safe'], [['area', 'video_url', 'supplier_name'], 'string'], [['stbz_goods_id', 'is_selection'], 'integer'], [['jst_goods_id', 'jst_supplier_id'], 'safe'], // ['g_pic_list',function ($attribute, $params) { // if(!is_array($this->g_pic_list)){ // $this->addError('g_pic_list','g_pic_list is not array!'); // } // }], ]; } //订单取消审核 public function getLastOrderInfo(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $cacheK_id = 'id_SupplierForm_getLastOrderInfo_maxId_' . $this->token_supplier_id . $this->supplier_id; $cacheK_purchase_order_id = 'purchase_order_id_SupplierForm_getLastOrderInfo_maxId_' . $this->token_supplier_id . $this->supplier_id; $cacheV_id = (int)cache()->get($cacheK_id); $cacheV_purchase_order_id = (int)cache()->get($cacheK_purchase_order_id); $url = "/cloud/supplier/getLastOrderInfo"; $data = []; $data['access_token'] = get_supplier_token($this->token_supplier_id, $this->supplier_id); //获取供货商的token信息 $data['purchase_order_id'] = $cacheV_purchase_order_id; //订单id $data['id'] = $cacheV_id; //订单id $res = cloud_post($this->domain.$url,$data); // var_dump($res, $url, $data); $res = json_decode($res,true); if($res['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$res['msg']); }else{ if($res['data']){ if($res['data']['order_info']){ cache()->set($cacheK_id, $res['data']['order_info']['id']); } if($res['data']['purchase_order_info']){ cache()->set($cacheK_purchase_order_id, $res['data']['purchase_order_info']['id']); } } return $this->outPutData($res['code'],$res['msg'],$res['data']); } } //订单取消审核 public function supplierOrderCancel(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $supplier_order_cancel_url = "/cloud/supplier/supplierOrderCancel"; $supplier_order_cancel_data = []; $supplier_order_cancel_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息 $supplier_order_cancel_data['order_id'] = $this->order_id; //订单id $supplier_order_cancel_data['cancel_type'] = $this->cancel_type; //1 通过 2 拒绝 $supplierOrderCancelInfo = cloud_post($this->domain.$supplier_order_cancel_url,$supplier_order_cancel_data); $supplierOrderCancelInfo = json_decode($supplierOrderCancelInfo,true); if($supplierOrderCancelInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierOrderCancelInfo['msg']); }else{ // if ((int)$this->cancel_type === 1) { // $purchase_order = PurchaseOrder::findOne(['cloud_order_id' => $this->order_id]); // if ($purchase_order && (int)$purchase_order->pay_type === 1) { // $res = WechatBusinessPay::orderRefund($purchase_order, OrderNo::ORDER_ALLIANCE_PURCHASE, $purchase_order->pay_price, 'POR' . $purchase_order->order_no); // if ($res['code'] === 1) { // return $res; // } // } // } if (intval($this->cancel_type) === 1) { $purchaseOrder = PurchaseOrder::findOne(['cloud_order_id' => $this->order_id]); try { $supplier = Supplier::findOne(['cloud_supplier_id' => $purchaseOrder->cloud_supplier_id]); $printer_order = new PrintOrder(0, $this->order_id, 'confirm', 0, 0, 1, 0, $supplier->id); $printer_order->print_order(); } catch (\Exception $e) { debug_log([ 'event' => 'supplierOrderCancel', 'message' => $e->getMessage(), 'line' => $e->getLine(), 'file' => $e->getFile() ], 'cloud_printer.log'); } } return $this->outPutData($supplierOrderCancelInfo['code'],$supplierOrderCancelInfo['msg']); } } //获取运费规则 public function supplierGetRules(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $supplier_get_rules_url = "/cloud/supplier/supplierGetRules"; $supplier_get_rules_data = []; $supplier_get_rules_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息 $supplier_get_rules_data['id'] = $this->id; $supplierGetRulesInfo = cloud_post($this->domain.$supplier_get_rules_url,$supplier_get_rules_data); $supplierGetRulesInfo = json_decode($supplierGetRulesInfo,true); if($supplierGetRulesInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierGetRulesInfo['msg']); }else{ return $this->outPutData($supplierGetRulesInfo['code'],$supplierGetRulesInfo['msg'],$supplierGetRulesInfo['data']); } } //删除运费规则 public function supplierDelRules(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $supplier_get_rules_url = "/cloud/supplier/supplierDelRules"; $supplier_get_rules_data = []; $supplier_get_rules_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息 $supplier_get_rules_data['id'] = $this->id; $supplierGetRulesInfo = cloud_post($this->domain.$supplier_get_rules_url,$supplier_get_rules_data); $supplierGetRulesInfo = json_decode($supplierGetRulesInfo,true); if($supplierGetRulesInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierGetRulesInfo['msg']); }else{ return $this->outPutData($supplierGetRulesInfo['code'],$supplierGetRulesInfo['msg'],$supplierGetRulesInfo['data']); } } //修改运费规则状态 public function supplierSetStatus(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $supplier_get_rules_url = "/cloud/supplier/supplierSetStatus"; $supplier_get_rules_data = []; $supplier_get_rules_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息 $supplier_get_rules_data['id'] = $this->id; $supplier_get_rules_data['is_default'] = $this->is_default; $supplierGetRulesInfo = cloud_post($this->domain.$supplier_get_rules_url,$supplier_get_rules_data); $supplierGetRulesInfo = json_decode($supplierGetRulesInfo,true); if($supplierGetRulesInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierGetRulesInfo['msg']); }else{ return $this->outPutData($supplierGetRulesInfo['code'],$supplierGetRulesInfo['msg'],$supplierGetRulesInfo['data']); } } //获取运费规则 public function supplierGetRulesList(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $supplier_get_rules_url = "/cloud/supplier/supplierGetRulesList"; $supplier_get_rules_data = []; $supplier_get_rules_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息 $supplierGetRulesInfo = cloud_post($this->domain.$supplier_get_rules_url,$supplier_get_rules_data); $supplierGetRulesInfo = json_decode($supplierGetRulesInfo,true); if($supplierGetRulesInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierGetRulesInfo['msg']); }else{ return $this->outPutData($supplierGetRulesInfo['code'],$supplierGetRulesInfo['msg'],$supplierGetRulesInfo['data']); } } //供货单订单发货 public function supplierOrderSend($cloud_supplier_id = 0){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } if (!empty($this->xlsx)) { $supplier_order_send_url = "/cloud/supplier/supplierOrderAllSend"; $supplier_order_send_data = []; $supplier_order_send_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息 $xlsx_path = $this->saveTempImage($this->xlsx); $rows = SimpleExcelReader::create($xlsx_path)->noHeaderRow()->getRows(); $array = []; $rows->each(function($rowProperties) use (&$array) { array_push($array, $rowProperties); }); unset($array[0]); $array = array_values($array); $supplier_order_send_data['xlsx'] = json_encode($array); } else { $supplier_order_send_url = "/cloud/supplier/supplierOrderSend"; $supplier_order_send_data = []; $supplier_order_send_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息 $supplier_order_send_data['order_ids'] = $this->order_id; //订单ID $supplier_order_send_data['express_name'] = $this->express_name; //快递公司 $supplier_order_send_data['express_no'] = $this->express_no; //快递号 $supplier_order_send_data['send_type'] = $this->send_type; //1 快递配送 2 自主配送 } $supplierOrderSendInfo = cloud_post($this->domain.$supplier_order_send_url,$supplier_order_send_data); $supplierOrderSendInfo = json_decode($supplierOrderSendInfo,true); if($supplierOrderSendInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierOrderSendInfo['msg']); }else{ if (!empty($array)) { foreach ($array as $item) { $order = PurchaseOrder::find()->where(['cloud_order_id' => $this->order_id])->one(); $of = new OrderForm(); $of->order_id = $order->id; $of->express = $this->express_name; $of->express_no = $this->express_no; $of->words = $this->words; $res = $of->send(); if ($res['code'] !== 0) { return $res; } } } return $this->outPutData($supplierOrderSendInfo['code'],$supplierOrderSendInfo['msg']); } } //供货单订单删除 public function supplierOrderDel(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $supplier_order_send_url = "/cloud/supplier/supplierOrderDel"; $supplier_order_send_data = []; $supplier_order_send_data['access_token'] = get_supplier_token(); //获取供货商的token信息 $supplier_order_send_data['order_ids'] = $this->order_id; //订单ID $supplierOrderSendInfo = cloud_post($this->domain.$supplier_order_send_url,$supplier_order_send_data); $supplierOrderSendInfo = json_decode($supplierOrderSendInfo,true); if($supplierOrderSendInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierOrderSendInfo['msg']); }else{ return $this->outPutData($supplierOrderSendInfo['code'],$supplierOrderSendInfo['msg']); } } //供货单修改收货地址 / 卖家备注 public function supplierOrderSetAddress(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $supplier_order_send_url = "/cloud/supplier/setOrderAddress"; $supplier_order_send_data = []; $supplier_order_send_data['access_token'] = get_supplier_token(); //获取供货商的token信息 $supplier_order_send_data['order_id'] = $this->order_id; $supplier_order_send_data['address_data'] = $this->address_data; $supplier_order_send_data['remark'] = $this->seller_comments; $supplier_order_send_data['order_type'] = $this->order_type; $supplierOrderSendInfo = cloud_post($this->domain.$supplier_order_send_url,$supplier_order_send_data); $supplierOrderSendInfo = json_decode($supplierOrderSendInfo,true); if($supplierOrderSendInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierOrderSendInfo['msg']); }else{ if (intval($this->order_type)) { $order = PurchaseOrder::find()->where(['cloud_order_id' => $this->order_id])->one(); $address_data = json_decode($this->address_data, true); if($address_data){ $order->province_id = $address_data['province']; $order->city_id = $address_data['city']; $order->district_id = $address_data['district']; $order->address = $address_data['address']; $order->name = $address_data['name']; $order->mobile = $address_data['mobile']; } if($this->seller_comments){ $order->seller_comments = $this->seller_comments; } $order->save(); } return $this->outPutData($supplierOrderSendInfo['code'],$supplierOrderSendInfo['msg']); } } //供货单修改收货地址 / 卖家备注 public function supplierPurchaseOrderSetAddress(){//setPurchaseOrderAddress if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $supplier_order_send_url = "/cloud/supplier/setPurchaseOrderAddress"; $supplier_order_send_data = []; $supplier_order_send_data['access_token'] = get_supplier_token(); //获取供货商的token信息 $supplier_order_send_data['order_id'] = $this->order_id; $supplier_order_send_data['address_data'] = $this->address_data; $supplier_order_send_data['remark'] = $this->seller_comments; $supplier_order_send_data['order_type'] = $this->order_type; $supplierOrderSendInfo = cloud_post($this->domain.$supplier_order_send_url,$supplier_order_send_data); $supplierOrderSendInfo = json_decode($supplierOrderSendInfo,true); if($supplierOrderSendInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierOrderSendInfo['msg']); }else{ $OrderTransit = OrderTransit::findOne(['cloud_order_id' => $this->order_id]); $order = Order::find()->where(['id' => $OrderTransit->order_id])->one(); $address_data = json_decode($this->address_data); if($address_data){ $order->address = $address_data->address; $order->name = $address_data->name; $order->mobile = $address_data->mobile; } if($this->seller_comments){ $order->seller_comments = $this->seller_comments; } $order->save(); return $this->outPutData($supplierOrderSendInfo['code'],$supplierOrderSendInfo['msg']); } } //订单列表(新) public function supplierSendTypeList($cloud_supplier_id = 0){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } // 获取可导出数据 $f = new ExportList(); $exportList = $f->getList(); $supplier_order_list_url = "/cloud/supplier/supplierSendTypeList"; $supplier_order_list_data = []; $supplier_order_list_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息 $admin = get_admin(); if ($admin->type === 'admin' || $admin->type === Admin::ADMIN_TYPE_SAAS_STAFF) { $supplier_order_list_url = "/cloud/user/supplierPurchaseOrderList"; $supplier_order_list_data['access_token'] = get_platform_token(); // $admin = get_admin(); // $admin_id = $admin->id; // if ($admin->username == 'admin') { // $admin_id = null; // } // if ($admin_id) { // $admin_model = Admin::findOne($admin_id); // $area_level = $admin_model->area_level; $cloud_supplier_id = Supplier::find()->where(['is_delete' => 0])->select('cloud_supplier_id')->column(); if (!empty($cloud_supplier_id)) { $supplier_order_list_data['supplier_id'] = implode(',', $cloud_supplier_id); } if (!empty($this->supplier_name)) { $supplier_order_list_data['supplier_name'] = $this->supplier_name; } // $salesman_id = $this->salesman_id; // if ($salesman_id) { // $query->andWhere([ // 'salesman_id' => $salesman_id // ]); // } // if($area_level == 1){ // $query->andWhere( // ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]); // } elseif ($area_level == 2){ // $query->andWhere( // ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]); // } elseif ($area_level == 3){ // $query->andWhere(['province_id' => $admin_model->province_id]); // } // $ids = $query->select('cloud_supplier_id')->column(); // if ($ids) { // if(is_array($ids)){ // $ids = implode(',', $ids); // } // $supplier_order_list_data['supplier_id'] = $ids; // } else { // return $this->outPutData(0,'获取成功',[ // 'list' => [] // ]); // } // } } $supplier_order_list_data['page'] = $this->page; //订单ID $supplier_order_list_data['mobile'] = $this->mobile; //订单ID $supplier_order_list_data['user_name'] = $this->user_name; //订单ID $supplier_order_list_data['goods_name'] = $this->goods_name; //订单ID $supplier_order_list_data['limit'] = $this->limit; //1 取消通过 2 取消失败 $supplier_order_list_data['status'] = $this->status; //-1 全部 0 待供货商确认 1 供货商已发货 2 已确认收货 $supplier_order_list_data['mch_id'] = $this->could_mch_id; //商户ID $supplier_order_list_data['type'] = $this->type ?: 0; //订单类型0:快递 1:自助配送 2:云仓库存 6:仓库快递 if($this->start_time) $supplier_order_list_data['start_time'] = strtotime($this->start_time); //开始时间 if($this->end_time) $supplier_order_list_data['end_time'] = strtotime($this->end_time); //结束时间 if($this->order_no) $supplier_order_list_data['order_no'] = $this->order_no; //订单号 if($this->order_id) $supplier_order_list_data['order_id'] = $this->order_id; if (!empty(trim($this->mch_order_no))) { $mch_order_id = Order::find()->where(['LIKE', 'order_no', $this->mch_order_no])->select('id')->column(); if (!empty($mch_order_id)) { $mch_order_id = implode(',', $mch_order_id); } else { $mch_order_id = '-1'; } $supplier_order_list_data['mch_order_ids'] = $mch_order_id; } $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data); $supplierOrderListInfo = json_decode($supplierOrderListInfo,true); if($supplierOrderListInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierOrderListInfo['msg']); }else{ $msg = '查询成功'; $xlsx = \Yii::$app->request->hostInfo . '/web/statics/Template.xlsx'; $supplier_id = get_supplier_id(); $is_stbz = false; $supplier = Supplier::findOne($supplier_id); if ($supplier && $supplier->is_stbz == 1) { $is_stbz = true; } foreach ($supplierOrderListInfo['data']['list'] as &$item) { if (!empty($item['platform_order_no'])) { $item['mch_order_no'] = Order::findOne($item['platform_order_no'])->order_no; } else { $item['mch_order_no'] = PurchaseOrder::findOne(['cloud_order_id' => $item['id']])->order_no; } if ($item['mch_id']) { $store_cloud = StoreCloud::findOne(['cloud_store_id' => $item['mch_id'], 'is_delete' => 0]); if ($store_cloud) { $store = Store::findOne($store_cloud->store_id); $item['mch']['name'] = $store->name ?: $item['mch']['name']; // $item['user']['store_name'] = $store->name ?: $item['user']['store_name']; } } } $supplierOrderListInfo['data'] = array_merge($supplierOrderListInfo['data'], ['export_list' => $exportList, 'supplier_id' => $supplier_id, 'xlsx' => $xlsx, 'is_stbz' => $is_stbz]); return $this->outPutData($supplierOrderListInfo['code'], $msg, $supplierOrderListInfo['data']); } } //供货单列表 public function supplierOrderList($cloud_supplier_id = 0){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } // 获取可导出数据 $f = new ExportList(); $exportList = $f->getList(); $supplier_order_list_url = "/cloud/supplier/supplierOrderList"; $supplier_order_list_data = []; $supplier_order_list_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息 $admin = get_admin(); if ($admin->type === 'admin' || $admin->type === Admin::ADMIN_TYPE_FRONT_AGENT) { $supplier_order_list_url = "/cloud/user/supplierOrderList"; $supplier_order_list_data['access_token'] = get_platform_token(); $admin = get_admin(); $admin_id = $admin->id; if ($admin->username == 'admin') { $admin_id = null; } if ($admin_id) { $admin_model = Admin::findOne($admin_id); $area_level = $admin_model->area_level; $query = Supplier::find()->where(['is_delete' => 0]); $salesman_id = $this->salesman_id; if ($salesman_id) { $query->andWhere([ 'salesman_id' => $salesman_id ]); } if($area_level == 1){ $query->andWhere( ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]); } elseif ($area_level == 2){ $query->andWhere( ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]); } elseif ($area_level == 3){ $query->andWhere(['province_id' => $admin_model->province_id]); } $ids = $query->select('cloud_supplier_id')->column(); if ($ids) { if(is_array($ids)){ $ids = implode(',', $ids); } $supplier_order_list_data['supplier_id'] = $ids; } else { return $this->outPutData(0,'获取成功',[ 'list' => [] ]); } } } $supplier_order_list_data['page'] = $this->page; //订单ID $supplier_order_list_data['mobile'] = $this->mobile; //订单ID $supplier_order_list_data['user_name'] = $this->user_name; //订单ID $supplier_order_list_data['goods_name'] = $this->goods_name; //订单ID $supplier_order_list_data['limit'] = $this->limit; //1 取消通过 2 取消失败 $supplier_order_list_data['status'] = $this->status; //-1 全部 0 待供货商确认 1 供货商已发货 2 已确认收货 $supplier_order_list_data['mch_id'] = $this->could_mch_id; //商户ID $supplier_order_list_data['type'] = $this->type ?: 0; //商户ID if($this->start_time) $supplier_order_list_data['start_time'] = strtotime($this->start_time); //开始时间 if($this->end_time) $supplier_order_list_data['end_time'] = strtotime($this->end_time); //结束时间 if($this->order_no) $supplier_order_list_data['order_no'] = $this->order_no; //订单号 if($this->order_id) $supplier_order_list_data['order_id'] = $this->order_id; $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data); $supplierOrderListInfo = json_decode($supplierOrderListInfo,true); if($supplierOrderListInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierOrderListInfo['msg']); }else{ $msg = '查询成功'; $xlsx = \Yii::$app->request->hostInfo . '/web/statics/Template.xlsx'; $supplier_id = get_supplier_id(); $is_stbz = false; $supplier = Supplier::findOne($supplier_id); if ($supplier && $supplier->is_stbz == 1) { $is_stbz = true; } $supplierOrderListInfo['data'] = array_merge($supplierOrderListInfo['data'], ['export_list' => $exportList, 'supplier_id' => $supplier_id, 'xlsx' => $xlsx, 'is_stbz' => $is_stbz]); return $this->outPutData($supplierOrderListInfo['code'], $msg, $supplierOrderListInfo['data']); } } //订单取消审核 public function supplierPurchaseCancel(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $supplier_purchase_cancel_url = "/cloud/supplier/supplierPurchaseCancel"; $supplier_purchase_cancel_data = []; $supplier_purchase_cancel_data['access_token'] = get_supplier_token(); //获取供货商的token信息 $supplier_purchase_cancel_data['order_id'] = $this->order_id; //订单ID $supplier_purchase_cancel_data['cancel_type'] = $this->cancel_type; //1 取消通过 2 取消失败 $supplierPurchaseCancelInfo = cloud_post($this->domain.$supplier_purchase_cancel_url,$supplier_purchase_cancel_data); $supplierPurchaseCancelInfo = json_decode($supplierPurchaseCancelInfo,true); if($supplierPurchaseCancelInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierPurchaseCancelInfo['msg']); }else{ if (intval($this->cancel_type) === 1) { try { $orderTransit = OrderTransit::findOne(['cloud_order_id' => $this->order_id]); $supplier = Supplier::findOne(['cloud_supplier_id' => $orderTransit->cloud_supplier_id]); $printer_order = new PrintOrder(0, $this->order_id, 'confirm', 0, 0, 1, 0, $supplier->id); $printer_order->print_order(); } catch (\Exception $e) { debug_log([ 'event' => 'supplierPurchaseCancel', 'message' => $e->getMessage(), 'line' => $e->getLine(), 'file' => $e->getFile() ], 'cloud_printer.log'); } } return $this->outPutData($supplierPurchaseCancelInfo['code'],$supplierPurchaseCancelInfo['msg']); } } //订单发货 public function supplierPurchaseSend($cloud_supplier_id = 0){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } if (!empty($this->xlsx)) { $supplier_purchase_send_url = "/cloud/supplier/supplierPurchaseXlsxSend"; $supplier_purchase_send_data = []; $supplier_purchase_send_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息 $xlsx_path = $this->saveTempImage($this->xlsx); $rows = SimpleExcelReader::create($xlsx_path)->noHeaderRow()->getRows(); $array = []; $rows->each(function($rowProperties) use (&$array) { array_push($array, $rowProperties); }); unset($array[0]); $array = array_values($array); $supplier_purchase_send_data['xlsx'] = json_encode($array); } else { $supplier_purchase_send_url = "/cloud/supplier/supplierPurchaseSend"; $supplier_purchase_send_data = []; $supplier_purchase_send_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息 $supplier_purchase_send_data['order_ids'] = $this->order_id; //订单ID $supplier_purchase_send_data['express_name'] = $this->express_name; //快递公司 $supplier_purchase_send_data['express_no'] = $this->express_no; //快递号 $supplier_purchase_send_data['send_type'] = $this->send_type; //1 快递配送 2 自主配送 $supplier_purchase_send_data['words'] = $this->words; $supplier_purchase_send_data['zip_code'] = $this->zip_code; } $supplierPurchaseSendInfo = cloud_post($this->domain.$supplier_purchase_send_url,$supplier_purchase_send_data); $supplierPurchaseSendInfo = json_decode($supplierPurchaseSendInfo,true); if($supplierPurchaseSendInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierPurchaseSendInfo['msg']); }else{ return $this->outPutData($supplierPurchaseSendInfo['code'],$supplierPurchaseSendInfo['msg']); } } //订单修改发货信息 public function updateOrderSendInfo($cloud_supplier_id = 0){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $supplier_purchase_send_url = "/cloud/supplier/updateOrderSendInfo"; $supplier_purchase_send_data = []; $supplier_purchase_send_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息 $supplier_purchase_send_data['order_id'] = $this->order_id; //订单ID $supplier_purchase_send_data['express_name'] = $this->express_name; //快递公司 $supplier_purchase_send_data['express_no'] = $this->express_no; //快递号 $supplier_purchase_send_data['send_type'] = $this->send_type; //1 快递配送 2 自主配送 $supplier_purchase_send_data['words'] = $this->words; $supplier_purchase_send_data['zip_code'] = $this->zip_code; $supplier_purchase_send_data['order_type'] = $this->order_type; $supplierPurchaseSendInfo = cloud_post($this->domain.$supplier_purchase_send_url,$supplier_purchase_send_data); $supplierPurchaseSendInfo = json_decode($supplierPurchaseSendInfo,true); if($supplierPurchaseSendInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierPurchaseSendInfo['msg']); }else{ return $this->outPutData($supplierPurchaseSendInfo['code'],$supplierPurchaseSendInfo['msg']); } } //订单删除 public function supplierPurchaseDel(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $supplier_purchase_send_url = "/cloud/supplier/supplierPurchaseDel"; $supplier_purchase_send_data = []; $supplier_purchase_send_data['access_token'] = get_supplier_token(); //获取供货商的token信息 $supplier_purchase_send_data['order_ids'] = $this->order_id; //订单ID $supplierPurchaseSendInfo = cloud_post($this->domain.$supplier_purchase_send_url,$supplier_purchase_send_data); $supplierPurchaseSendInfo = json_decode($supplierPurchaseSendInfo,true); if($supplierPurchaseSendInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierPurchaseSendInfo['msg']); }else{ return $this->outPutData($supplierPurchaseSendInfo['code'],$supplierPurchaseSendInfo['msg']); } } //转单列表 public function supplierPurchaseOrderList($cloud_supplier_id = 0, $auto = 0){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } // 获取可导出数据 $f = new ExportList(); $exportList = $f->getList(); $admin = null; if ($auto === 0) { $admin = get_admin(); } $supplier_purchase_order_list_url = "/cloud/supplier/supplierPurchaseOrderList"; $supplier_purchase_order_list_data = []; $supplier_purchase_order_list_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息 if (($admin->type === 'admin' && $admin->username !== 'admin') || $admin->type === Admin::ADMIN_TYPE_FRONT_AGENT) { $supplier_purchase_order_list_url = "/cloud/user/supplierPurchaseOrderList"; $supplier_purchase_order_list_data['access_token'] = get_platform_token(); $admin_id = $admin->id; if ($admin_id) { $admin_model = Admin::findOne($admin_id); $area_level = $admin_model->area_level; $query = Supplier::find()->where(['is_delete' => 0]); $salesman_id = $this->salesman_id; if ($salesman_id) { $query->andWhere([ 'salesman_id' => $salesman_id ]); } if($area_level == 1){ $query->andWhere( ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]); } elseif ($area_level == 2){ $query->andWhere( ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]); } elseif ($area_level == 3){ $query->andWhere(['province_id' => $admin_model->province_id]); } $ids = $query->select('cloud_supplier_id')->column(); if ($ids) { if(is_array($ids)){ $ids = implode(',', $ids); } $supplier_purchase_order_list_data['supplier_id'] = $ids; } else { return $this->outPutData(0,'获取成功',[ 'list' => [] ]); } } } $supplier_purchase_order_list_data['page'] = $this->page; //默认为 1 $supplier_purchase_order_list_data['limit'] = $this->limit; //默认20 $supplier_purchase_order_list_data['status'] = $this->status; //-1 全部 0 待供货商确认 1 供货商已发货 2 已确认收货 $supplier_purchase_order_list_data['mch_id'] = $this->could_mch_id; //商户ID if($this->start_time) $supplier_purchase_order_list_data['start_time'] = strtotime($this->start_time); //开始时间 if($this->end_time) $supplier_purchase_order_list_data['end_time'] = strtotime($this->end_time); //结束时间 if($this->order_no) $supplier_purchase_order_list_data['order_no'] = $this->order_no; //订单号 if($this->order_id) $supplier_purchase_order_list_data['order_id'] = $this->order_id; //订单号 $supplierPurchaseOrderListInfo = cloud_post($this->domain.$supplier_purchase_order_list_url,$supplier_purchase_order_list_data); $supplierPurchaseOrderListInfo = json_decode($supplierPurchaseOrderListInfo,true); if($supplierPurchaseOrderListInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierPurchaseOrderListInfo['msg']); }else{ $msg = '获取成功'; $data = $supplierPurchaseOrderListInfo['data']; if ($auto === 0) { $xlsx = \Yii::$app->request->hostInfo . '/web/statics/Template.xlsx'; $is_stbz = false; $supplier_id = get_supplier_id(); $supplier = Supplier::findOne($supplier_id); if ($supplier && $supplier->is_stbz == 1) { $is_stbz = true; } $data = array_merge([ 'export_list' => $exportList, 'supplier_id' => $supplier_id, 'xlsx' => $xlsx, 'is_stbz' => $is_stbz, ], $data); } return $this->outPutData($supplierPurchaseOrderListInfo['code'],$msg,$data); } } public function supplierSendTypeRefundList() { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $supplier_purchase_order_list_url = "/cloud/supplier/supplierSendTypeRefundList"; $supplier_purchase_order_list_data = []; $supplier_purchase_order_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息 $admin = get_admin(); if ($admin->type === 'admin' || $admin->type === Admin::ADMIN_TYPE_FRONT_AGENT) { $supplier_purchase_order_list_url = "/cloud/user/supplierPurchaseOrderRefundList"; $supplier_purchase_order_list_data['access_token'] = get_platform_token(); $admin = get_admin(); $admin_id = $admin->id; if ($admin->username == 'admin') { $admin_id = null; } if ($admin_id) { $admin_model = Admin::findOne($admin_id); $area_level = $admin_model->area_level; $query = Supplier::find()->where(['is_delete' => 0]); $salesman_id = $this->salesman_id; if ($salesman_id) { $query->andWhere([ 'salesman_id' => $salesman_id ]); } if($area_level == 1){ $query->andWhere( ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]); } elseif ($area_level == 2){ $query->andWhere( ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]); } elseif ($area_level == 3){ $query->andWhere(['province_id' => $admin_model->province_id]); } $ids = $query->select('cloud_supplier_id')->column(); if ($ids) { if(is_array($ids)){ $ids = implode(',', $ids); } $supplier_purchase_order_list_data['supplier_id'] = $ids; } else { return $this->outPutData(0,'获取成功',[ 'list' => [] ]); } } } $supplier_purchase_order_list_data['page'] = $this->page; //默认为 1 $supplier_purchase_order_list_data['limit'] = $this->limit; //默认20 $supplier_purchase_order_list_data['status'] = $this->status; //-1 全部 0 待供货商确认 1 供货商已发货 2 已确认收货 $supplier_purchase_order_list_data['type'] = $this->type; if($this->start_time) $supplier_purchase_order_list_data['start_time'] = strtotime($this->start_time); //开始时间 if($this->end_time) $supplier_purchase_order_list_data['end_time'] = strtotime($this->end_time); //结束时间 if($this->order_no) $supplier_purchase_order_list_data['order_no'] = $this->order_no; //订单号 if($this->old_order_no) $supplier_purchase_order_list_data['old_order_no'] = $this->old_order_no; //订单号 if (!empty(trim($this->mch_order_no))) { $mch_order_id = Order::find()->where(['LIKE', 'order_no', $this->mch_order_no])->select('id')->column(); if (!empty($mch_order_id)) { $mch_order_id = implode(',', $mch_order_id); } else { $mch_order_id = '-1'; } $supplier_purchase_order_list_data['mch_order_ids'] = $mch_order_id; } $supplierPurchaseOrderListInfo = cloud_post($this->domain.$supplier_purchase_order_list_url,$supplier_purchase_order_list_data); $supplierPurchaseOrderListInfo = json_decode($supplierPurchaseOrderListInfo,true); if($supplierPurchaseOrderListInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierPurchaseOrderListInfo['msg']); }else{ foreach ($supplierPurchaseOrderListInfo['data']['list'] as &$item) { $order = Order::findOne(['id' => $item['platform_order_no']]); $item['platform_order_no'] = $order->order_no ?: ''; } $msg = '获取成功'; return $this->outPutData($supplierPurchaseOrderListInfo['code'],$msg,$supplierPurchaseOrderListInfo['data']); } } //转单售后列表 public function supplierPurchaseOrderRefundList(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $supplier_purchase_order_list_url = "/cloud/supplier/supplierPurchaseOrderRefundList"; $supplier_purchase_order_list_data = []; $supplier_purchase_order_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息 $admin = get_admin(); if ($admin->type === 'admin' || $admin->type === Admin::ADMIN_TYPE_FRONT_AGENT) { $supplier_purchase_order_list_url = "/cloud/user/supplierPurchaseOrderRefundList"; $supplier_purchase_order_list_data['access_token'] = get_platform_token(); $admin = get_admin(); $admin_id = $admin->id; if ($admin->username == 'admin') { $admin_id = null; } if ($admin_id) { $admin_model = Admin::findOne($admin_id); $area_level = $admin_model->area_level; $query = Supplier::find()->where(['is_delete' => 0]); $salesman_id = $this->salesman_id; if ($salesman_id) { $query->andWhere([ 'salesman_id' => $salesman_id ]); } if($area_level == 1){ $query->andWhere( ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]); } elseif ($area_level == 2){ $query->andWhere( ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]); } elseif ($area_level == 3){ $query->andWhere(['province_id' => $admin_model->province_id]); } $ids = $query->select('cloud_supplier_id')->column(); if ($ids) { if(is_array($ids)){ $ids = implode(',', $ids); } $supplier_purchase_order_list_data['supplier_id'] = $ids; } else { return $this->outPutData(0,'获取成功',[ 'list' => [] ]); } } } $supplier_purchase_order_list_data['page'] = $this->page; //默认为 1 $supplier_purchase_order_list_data['limit'] = $this->limit; //默认20 $supplier_purchase_order_list_data['status'] = $this->status; //-1 全部 0 待供货商确认 1 供货商已发货 2 已确认收货 $supplier_purchase_order_list_data['mch_id'] = $this->could_mch_id; //商户ID $supplier_purchase_order_list_data['order_type'] = $this->order_type; if($this->start_time) $supplier_purchase_order_list_data['start_time'] = strtotime($this->start_time); //开始时间 if($this->end_time) $supplier_purchase_order_list_data['end_time'] = strtotime($this->end_time); //结束时间 if($this->order_no) $supplier_purchase_order_list_data['order_no'] = $this->order_no; //订单号 $supplierPurchaseOrderListInfo = cloud_post($this->domain.$supplier_purchase_order_list_url,$supplier_purchase_order_list_data); $supplierPurchaseOrderListInfo = json_decode($supplierPurchaseOrderListInfo,true); if($supplierPurchaseOrderListInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierPurchaseOrderListInfo['msg']); }else{ $msg = '获取成功'; return $this->outPutData($supplierPurchaseOrderListInfo['code'],$msg,$supplierPurchaseOrderListInfo['data']); } } //供货商创建提现申请 public function storeSetSupplierCash(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $supplier_id = get_supplier_id(); if(!$supplier_id || $supplier_id < 0){ $code = 1; //失败 $msg = "会员信息有误!"; return $this->outPutData($code,$msg); } $supplierInfo = Supplier::find()->where(['id'=>$supplier_id,'is_delete'=>0])->one(); if(!$supplierInfo || !$supplierInfo['cloud_user_id'] || $supplierInfo['cloud_user_id'] < 0){ $code = 1; //失败 $msg = "会员信息有误!"; return $this->outPutData($code,$msg); } $supplier_cash_url = "/cloud/supplier/storeSetSupplierCash"; $supplier_cash_data = []; $supplier_cash_data['access_token'] = get_supplier_token(); //获取供货商的token信息 $supplier_cash_data['user_id'] = $supplierInfo['cloud_user_id']; //会员Id $supplier_cash_data['price'] = number_format($this->price, 2,".",""); //充值金额 $supplier_cash_data['type'] = $this->type; //类型 0 会员 1 商户 2 供货商 暂时仅做供货商提现 $supplier_cash_data['cash_type'] = $this->cash_type; //提现方式 1--微信支付 2--支付宝 3--银行卡 $supplier_cash_data['account'] = $this->account; //账号 微信 支付宝 银行卡号 $supplier_cash_data['name'] = $this->name; //姓名 $supplier_cash_data['bank_name'] = $this->bank_name; //银行 $supplierCashInfo = cloud_post($this->domain.$supplier_cash_url,$supplier_cash_data); $supplierCashInfo = json_decode($supplierCashInfo,true); if($supplierCashInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierCashInfo['msg']); }else{ return $this->outPutData($supplierCashInfo['code'],$supplierCashInfo['msg']); } } //处理请求 public function supplierApplyHandle($cloud_supplier_id = 0) { try { /** * is_agree 1 同意退换货 * is_agree 2 拒绝退换货 拒绝原因 * 判断type (商户申请状态 1退货退款 2换货) * * is_agree 1 status 1 确认收货 type = 1 打款完成 * is_agree 1 status 1 确认收货 type = 2 处理换货 * is_agree 2 || status 2 已经拒绝 */ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $is_agree = (int)$this->is_agree; $status = (int)$this->status; $reason = $this->reason; $order_id = (int)$this->order_id; $mobile = $this->mobile; $name = $this->name; $detail = $this->detail; $zipcode = $this->zipcode; if ($is_agree === 2 || $status === 2) { if (empty($reason)) { $code = 1; //失败 $msg = "请填写拒绝原因"; return $this->outPutData($code,$msg); } } $supplier_apply_url = "/cloud/supplier/supplierApplyHandle"; $supplier_apply_data = []; $supplier_apply_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息 $supplier_apply_data['is_agree'] = $is_agree; $supplier_apply_data['status'] = $status; $supplier_apply_data['reason'] = $reason; $supplier_apply_data['mobile'] = $mobile; $supplier_apply_data['name'] = $name; $supplier_apply_data['detail'] = $detail; $supplier_apply_data['zipcode'] = $zipcode; $supplier_apply_data['order_id'] = $order_id; $supplierApplyInfo = cloud_post($this->domain.$supplier_apply_url,$supplier_apply_data); $supplierApplyInfo = json_decode($supplierApplyInfo,true); debug_log($supplierApplyInfo, 'supplierApplyHandle.log'); // if(input_params('debug')){ // var_dump($supplierApplyInfo);die; // } if($supplierApplyInfo['code'] != 0){ $code = 1; //失败 throw new \Exception($supplierApplyInfo['msg']); }else{ $data = $supplierApplyInfo['data']; if ((int)$data['order_type'] === 0) { $order = OrderTransit::findOne(['cloud_order_id' => $data['order_id']]); if ($order && intval($order->status) === 0 && $is_agree === 1) {//未发货状态申请售后,直接调用退款 $status = 1; } //只查询一条订单详情记录 $cancel_examine_item_info = []; $cancel_examine_info = json_decode($order->cancel_examine_info, true); debug_log(['cancel_examine_info' => $cancel_examine_info], 'supplierRefund.log'); debug_log(['order_detail' => $data['order_detail']], 'supplierRefund.log'); if ($cancel_examine_info) { foreach ($cancel_examine_info as $cancel_examine_item) { foreach ($data['order_detail'] as $detail_item) { if ($cancel_examine_item['cloud_goods_id'] == $detail_item['goods_id'] && $cancel_examine_item['goods_no'] == $detail_item['goods_no']) { //符合条件 修改状态 debug_log(['cancel_examine_item_' => $cancel_examine_item_info], 'supplierRefund.log'); $cancel_examine_item_info[] = $cancel_examine_item; } } } debug_log(['cancel_examine_item' => $cancel_examine_item_info], 'supplierRefund.log'); //查询售后订单 售后订单不止一条可能会有问题 //20241106 增加多条售后订单记录流程 $store_order_detail_id = array_column($cancel_examine_item_info, 'store_order_detail_id'); sort($store_order_detail_id); //目前提交售后要么就是全部提交 要么就是单个单个提交 $orderRefund = null; $orderRefundList = OrderRefund::find()->where(['order_id' => $order->order_id])->asArray()->all(); //假设全部提交情况下 // debug_log(['orderRefundList' => $orderRefundList], 'supplierRefund.log'); foreach ($orderRefundList as $orderRefundItem) { $refund_detail_id = json_decode($orderRefundItem['order_detail_id'], true); sort($refund_detail_id); debug_log([ 'id' => $orderRefundItem['id'], 'refund_detail_id' => $refund_detail_id, 'store_order_detail_id' => $store_order_detail_id, 'bool' => !array_diff($store_order_detail_id, $refund_detail_id) ], 'supplierRefund.log'); if (!array_diff($store_order_detail_id, $refund_detail_id)) { $orderRefund = OrderRefund::findOne($orderRefundItem['id']); } } //全部提交情况不存在 列出单个提交的情况 if (!$orderRefund) { foreach ($orderRefundList as $orderRefundItem) { $refund_detail_id = json_decode($orderRefundItem['order_detail_id'], true); if (in_array($refund_detail_id[0], $store_order_detail_id)) { $orderRefund = OrderRefund::findOne($orderRefundItem['id']); } } } //以上情况都不存在 if (empty($orderRefund)) { throw new \Exception('售后订单不存在'); } } else { $orderRefund = OrderRefund::findOne([ 'order_id' => $order->order_id ]); } //如果同意售后就修改商城订单状态,且更改地址为供货商地址信息 if ($is_agree === 1) { if ($orderRefund) { //供货商同意之后将商城订单状态修改为同意 $orderRefund->is_agree = 1; $orderRefund->address_id = 0; $orderRefund->refund_address = json_encode( [ 'name' => $name, 'address' => $detail, 'mobile' => $mobile ] , JSON_UNESCAPED_UNICODE); } } } else { $order = PurchaseOrder::findOne(['cloud_order_id' => $data['order_id']]); if ($order && intval($order->trade_status) === 0 && $is_agree === 1) { $status = 1; } } if ((int)$status === 1) { if ((int)$data['order_type'] === 1) { $order->trade_status = 1; } else { $order->status = -1; } $order->cancel_examine = 2; if ($data) { //微信支付退款操作 if (isset($order->pay_type) && (int)$order->pay_type === 1) { $res = WechatBusinessPay::orderRefund($order, OrderNo::ORDER_ALLIANCE_PURCHASE, $data['refund_price'], $data['order_refund_no']); if ($res['code'] === 1) { return $res; } } } // 赤店新增逻辑 未进件情况下转单需要从商城余额抵扣金额 ... // 申请售后, 需要从商城金额扣款 (已经从用户到账金额里扣减了) // if (intval($order->is_use_platform_mch) && (int)$data['order_type'] === 0) { // $store_info = Store::findOne($order->store_id); // Store::addMoney($store_info, $order->order_price, '商城云仓订单售后'); // } //如果是转单订单 供货商取消之后需要原路退回金额 当前版本下用户申请售后 商家同意后 用户直接与供货商交互 ///流程为用户确认收货后-申请售后-商城同意售后-API(商城向供货商申请售后)-供货商同意后填写收货地址-用户在客户端可以看到供货商填写的手机号以及地址信息 ///用户发货-供货商后台进行收货-售后完成给商城用户退款 if ((int)$data['order_type'] === 0) { if (!empty($orderRefund)) { //给商城用户退款 $orderRefundForm = new OrderRefundForm(); $orderRefundForm->order_refund_id = $orderRefund->id; $orderRefundForm->store_id = $order->store_id; $orderRefundForm->type = 1; $orderRefundForm->action = 1; $orderRefundForm->refund = 1; $refund_result = $orderRefundForm->save(1); debug_log($refund_result, 'SupplierRefund.log'); } } $type = 1; if (intval($data['order_type'])) {//批发 $type = 2; } try { $supplier = Supplier::findOne(['cloud_supplier_id' => $order->cloud_supplier_id]); $printer_order = new PrintOrder(0, $order->cloud_order_id, 'confirm', 0, 0, $type, 0, $supplier->id); $printer_order->print_order(); } catch (\Exception $e) { debug_log([ 'event' => 'supplierApplyHandle', 'message' => $e->getMessage(), 'line' => $e->getLine(), 'file' => $e->getFile() ], 'cloud_printer.log'); } } if ($is_agree === 2 || $status === 2) { // $order->cancel_examine = 0; if ($is_agree === 2) { if (!empty($orderRefund)) { $orderRefund->is_agree = 2; $orderRefund->status = 2; } } if ($order->cancel_examine_info) { $cancel_examine_info = json_decode($order->cancel_examine_info, true); foreach ($cancel_examine_info as $cancel_examine_index => $cancel_examine_item) { foreach ($data['order_detail'] as $detail_item) { if ($cancel_examine_item['cloud_goods_id'] == $detail_item['goods_id'] && $cancel_examine_item['goods_no'] == $detail_item['goods_no']) { unset($cancel_examine_info[$cancel_examine_index]); } } } $order->cancel_examine_info = json_encode(array_values($cancel_examine_info)); } else { $order->cancel_examine = 0; } } if (!$order->save()) { throw new \Exception(json_encode($order->errors)); } if ($orderRefund && !$orderRefund->save()) { throw new \Exception(json_encode($order->errors)); } return $this->outPutData($supplierApplyInfo['code'],$supplierApplyInfo['msg']); } } catch (\Exception $e) { $code = 1; //失败 return $this->outPutData($code, $e->getMessage() . $e->getLine()); } } //余额记录 public function supplierGetBalanceLog(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $get_balance_log_url = "/cloud/supplier/supplierGetBalanceLog"; $get_balance_log_data = []; $get_balance_log_data['access_token'] = get_supplier_token(); //获取供货商的token信息 if($this->page) $get_balance_log_data['page'] = $this->page; //计费方式【1=>按重计费、2=>按件计费】 if($this->limit) $get_balance_log_data['limit'] = $this->limit; $getBalanceLogInfo = cloud_post($this->domain.$get_balance_log_url,$get_balance_log_data); $getBalanceLogInfo = json_decode($getBalanceLogInfo,true); if($getBalanceLogInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$getBalanceLogInfo['msg']); }else{ $msg = '获取成功'; return $this->outPutData($getBalanceLogInfo['code'],$msg,$getBalanceLogInfo['data']); } } //余额冻结记录 public function supplierGetBalanceFrozenLog(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $get_balance_log_url = "/cloud/supplier/supplierGetBalanceFrozenLog"; $get_balance_log_data = []; $get_balance_log_data['access_token'] = get_supplier_token(); //获取供货商的token信息 if($this->page) $get_balance_log_data['page'] = $this->page; //计费方式【1=>按重计费、2=>按件计费】 if($this->limit) $get_balance_log_data['limit'] = $this->limit; $getBalanceLogInfo = cloud_post($this->domain.$get_balance_log_url,$get_balance_log_data); $getBalanceLogInfo = json_decode($getBalanceLogInfo,true); if($getBalanceLogInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$getBalanceLogInfo['msg']); }else{ $msg = '获取成功'; return $this->outPutData($getBalanceLogInfo['code'],$msg,$getBalanceLogInfo['data']); } } //商品提交审核 public function auditSubmit(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $rules_url = "/cloud/supplier/supplierPutGoodsAudit"; $rules_data = []; $rules_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息 $rules_data['goods_id'] = $this->goods_id; //商品ID $rulesInfo = cloud_post($this->domain.$rules_url,$rules_data); $rulesInfo = json_decode($rulesInfo,true); if($rulesInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$rulesInfo['msg']); }else{ if ((int)$this->status === 0) { Goods::updateAll(['status' => 0], ['cloud_goods_id' => $this->goods_id, 'is_wholesale' => 0]); } $code = $rulesInfo['code']; return $this->outPutData($code,$rulesInfo['msg'], $rulesInfo['data']); } } //商品上下架 public function setRules(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $rules_url = "/cloud/supplier/supplierSetRules"; $rules_data = []; $rules_data['access_token'] = get_supplier_token(); //获取供货商的token信息 $rules_data['type'] = $this->type; //计费方式【1=>按重计费、2=>按件计费】 $rules_data['desc'] = $this->desc; $rules_data['id'] = $this->id; $rules_data['is_default'] = $this->is_default; $rules_data['name'] = $this->name; $rulesInfo = cloud_post($this->domain.$rules_url,$rules_data); $rulesInfo = json_decode($rulesInfo,true); if($rulesInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$rulesInfo['msg']); }else{ $code = $rulesInfo['code']; return $this->outPutData($code,$rulesInfo['msg']); } } //商品状态 public function setGoodsStatus(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $goods_status_url = "/cloud/supplier/supplierSetGoodsStatus"; $goods_status_data = []; $goods_status_data['access_token'] = get_supplier_token(); //获取供货商的token信息 $goods_status_data['goods_ids'] = $this->goods_id; //商品ID if(in_array($this->status,[0,1,2])){ $goods_status_data['status'] = $this->status; }//0 下架 1 上架 2删除 //检测胜天半子 if ($this->stbz_goods_id && intval($this->status) === 1) { $id = \get_params('id', $this->stbz_goods_id); $params = [ 'id' => $id, ]; $key = md5(json_encode(\array_merge($params, ['type' => 'stbz_get_goods_item']))); if (\Yii::$app->cache->exists($key)) { $data = \Yii::$app->cache->get($key); $returnData = \json_decode($data, true); } else { $data = \stbz_client()->getApiResponse('get', '/v2/Goods/Detail', $params); $returnData = \json_decode($data, true); if ($returnData['code'] != 1) { return [ 'code' => 1, 'msg' => $returnData['msg'], ]; } \Yii::$app->cache->set($key, $data, 600); } if (!$returnData['data']) { return [ 'code' => 1, 'msg' => '胜天半子商品不存在', ]; } if (intval($returnData['data']['status']) === 0) { return [ 'code' => 1, 'msg' => '胜天半子商品已下架', ]; } } $goodsStatusInfo = cloud_post($this->domain.$goods_status_url,$goods_status_data); $goodsStatusInfo = json_decode($goodsStatusInfo,true); if($goodsStatusInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$goodsStatusInfo['msg']); }else{ if (in_array($this->status, [0, 2])) { $goods_id = $this->goods_id; if (is_string($this->goods_id)) { $goods_id = explode(',', $this->goods_id); } Goods::updateAll(['status' => 0], ['cloud_goods_id' => $goods_id, 'is_wholesale' => 0]); } return $this->outPutData($goodsStatusInfo['code'] ,$goodsStatusInfo['msg']); } } //添加编辑规格 public function setGoodsAttr(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $goods_attr_url = "/cloud/supplier/supplierSetGoodsAttr"; $goods_attr_data = []; $goods_attr_data['access_token'] = get_supplier_token(); //获取供货商的token信息 $goods_attr_data['attr_id'] = ($this->attr_id) ? $this->attr_id : 0 ; //规格ID 0添加 大于0 编辑 $goods_attr_data['name'] = $this->name; //规格名称 $goods_attr_data['goods_id'] = $this->goods_id; //商品ID $goods_attr_data['price'] = number_format($this->price, 2,".",""); //价格 $goods_attr_data['pic_url'] = $this->pic_url; //规格图片 $goods_attr_data['num'] = $this->num; //库存 // $goods_attr_data['weight'] = $this->weight; $goods_attr_data['goods_no'] = $this->goods_no; //规格货号 $goodsAttrInfo = cloud_post($this->domain.$goods_attr_url,$goods_attr_data); $goodsAttrInfo = json_decode($goodsAttrInfo,true); if($goodsAttrInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$goodsAttrInfo['msg']); }else{ return $this->outPutData($goodsAttrInfo['code'],$goodsAttrInfo['msg']); } } //添加编辑规格 public function setGoodsAttrNum($supplier_id, $goods_id, $updateAttrList, $store_id = 0){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $goods_attr_url = "/cloud/supplier/setGoodsAttrNum"; $goods_attr_data = []; $goods_attr_data['access_token'] = get_supplier_token(0, $supplier_id); //获取供货商的token信息 $goods_attr_data['attrs'] = json_encode($updateAttrList); $store_id && $goods_attr_data['store_id'] = $store_id; $goods_attr_data['goods_id'] = $goods_id; //商品ID $setGoodsAttrNum = cloud_post($this->domain.$goods_attr_url,$goods_attr_data); $setGoodsAttrNum = json_decode($setGoodsAttrNum,true); if($setGoodsAttrNum['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$setGoodsAttrNum['msg']); }else{ return $this->outPutData($setGoodsAttrNum['code'],$setGoodsAttrNum['msg']); } } //创建商品 public function setGoods(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $price = number_format($this->g_price, 2,".",""); $goods_url = "/cloud/supplier/supplierSetGoods"; $goods_data = []; $goods_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息 $goods_data['goods_id'] = ($this->goods_id) ? $this->goods_id : 0; $goods_data['name'] = $this->name; //默认为 1 $goods_data['pic_url'] = $this->g_s_pic_url; $goods_data['video_url'] = $this->video_url; $goods_data['desc'] = $this->desc; $goods_data['num'] = $this->num; //库存 $goods_data['use_attr'] = $this->use_attr; //是否使用规格 默认0不使用 $goods_data['price'] = $price; //售价 $goods_data['wholesale_price'] = number_format((float)$this->g_wholesale_price, 2,".",""); // 批发价 $goods_data['wholesale_ladder_rebate'] = $this->g_wholesale_ladder_rebate; // 批发阶梯折扣 $goods_data['wholesale_rebate_switch'] = $this->g_wholesale_rebate_switch; // 是否开启批发阶梯折扣 $goods_data['wholesale_ladder_type'] = $this->wholesale_ladder_type; // 是否开启批发阶梯折扣 $goods_data['cat_id'] = $this->cat_id; $goods_data['sort'] = $this->sort; $goods_data['is_change'] = $this->is_change ?: 0; $goods_data['original_price'] = number_format($this->g_original_price, 2,".",""); //零售价 $goods_data['pic_list'] = json_encode($this->g_pic_list); $goods_data['is_purchase'] = $this->is_purchase; $goods_data['is_need_install'] = (int)$this->is_need_install; $goods_data['stbz_goods_id'] = $this->stbz_goods_id ?: 0; $goods_data['jst_goods_id'] = $this->jst_goods_id ?: 0; $goods_data['jst_supplier_id'] = $this->jst_supplier_id ?: 0; $goods_data['freight'] = (int)$this->freight; $goods_data['is_level'] = (int)$this->is_level; $goods_data['goods_full_give_switch'] = (int)$this->goods_full_give_switch; $goods_data['goods_full_give_info'] = $this->goods_full_give_info; $goods_data['market_price'] = $this->market_price ?: 0; $goods_data['underlined_price'] = sprintf('%.2f', $this->underlined_price); $goods_data['send_type_num'] = $this->send_type_num ?: 0; $goods_data['centralize_goods_type'] = $this->centralize_goods_type ?: 0; //增加平台协议价 $platform_negotiated_price = $this->setPlatformNegotiatedPrice($price); $goods_data['platform_negotiated_price'] = $platform_negotiated_price; if($this->goods_area_rules_id) $goods_data['goods_area_rules_id'] = $this->goods_area_rules_id; if($this->g_unit) $goods_data['unit'] = $this->g_unit; if($this->g_shop_count) $goods_data['shop_count'] = $this->g_shop_count; if($this->g_send_type) $goods_data['send_type'] = $this->g_send_type; if($this->goods_no) $goods_data['goods_no'] = $this->goods_no; //默认20 if ($this->weight) $goods_data['weight'] = number_format($this->weight, 2, '.', ''); // 重量,克 $is_supplier_set_price = Option::get('is_supplier_set_price', 0, 'cloud', 1)['value']; $goods_data['is_supplier_set_price'] = $is_supplier_set_price; $attrs = $this->attrs; foreach ($attrs as &$attr_item) { $attr_item['platform_negotiated_price'] = $this->setPlatformNegotiatedPrice($attr_item['price']); } $goods_data['attrs'] = json_encode($attrs); $goods_data['is_selection'] = $this->is_selection; $goodsDataInfo = cloud_post($this->domain.$goods_url,$goods_data); $goodsDataInfo = json_decode($goodsDataInfo,true); if($goodsDataInfo['code'] != 0){ $code = 1;//失败 return $this->outPutData($code,$goodsDataInfo['msg']); }else{ if (!empty($this->goods_id) && $goodsDataInfo['data']['open'] == true) { Goods::updateAll(['status' => 0],['cloud_goods_id' => $this->goods_id, 'is_wholesale' => 0]); } return $this->outPutData($goodsDataInfo['code'] ,$goodsDataInfo['msg'], $goodsDataInfo['data']); } } public function setPlatformNegotiatedPrice($price) { $platform_profit_strategy = Option::get('platform_profit_strategy', 0, 'store')['value']; $platform_profit_strategy = json_decode($platform_profit_strategy, true); if (!empty($platform_profit_strategy)) { //服务收费start if (intval($platform_profit_strategy['service_charge_model'])) { //平台溢价 $service_charge_rate = $platform_profit_strategy['service_charge_rate']; } else { //供货商抽成 $service_charge_rate = 0; } $price = sprintf('%.2f', ($price * (1 + ($service_charge_rate / 100)))); } return $price; } //获取商品列表 public function goodsList(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $goods_list_url = "/cloud/supplier/supplierGetGoodsList"; $goods_list_data = []; $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息 $goods_list_data['page'] = input_params('pageNo') ?: $this->page; //默认为 1 $goods_list_data['limit'] = $this->limit; //默认20 if($this->goods_id) $goods_list_data['goods_id'] = $this->goods_id; if($this->cat_id) $goods_list_data['cat_id'] = (int)$this->cat_id; if($this->supplier_id) $goods_list_data['supplier_id'] = $this->supplier_id; if($this->name) $goods_list_data['name'] = $this->name; //商品名称 if($this->status != -1) $goods_list_data['status'] = $this->status; //-1 全部 0 下架 1 上架 $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data); $goodsListInfo = json_decode($goodsListInfo,true); if($goodsListInfo['code'] != 0){ $code = 1;//失败 return $this->outPutData($code,$goodsListInfo['msg']); }else{ foreach ($goodsListInfo['data']['list'] as &$item) { $agent_goods = AgentGoodsBindGoods::find()->where(['cloud_goods_id' => $item['id'], 'is_delete' => 0]) ->select('goods_agent_admin_id') ->column(); $item['admin_list'] = Admin::find()->where( ['id' => $agent_goods, 'type' => Admin::ADMIN_TYPE_GOODS_AGENT, 'is_delete' => 0] )->select('id, name, address, mobile, province_id, city_id, district_id')->asArray()->all(); foreach ($item['admin_list'] as &$value) { $province_id = $value['province_id']; $city_id = $value['city_id']; $district_id = $value['district_id']; $district = District::find()->where(['id' => [$province_id, $city_id, $district_id]])->select('name')->column(); $value['address'] = implode('', $district) . $value['address']; } } return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']); } } //获取商品审核列表 public function goodsAuditList(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $goods_list_url = "/cloud/supplier/supplierGetGoodsAuditList"; $goods_list_data = []; $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息 $goods_list_data['page'] = $this->page; //默认为 1 $goods_list_data['limit'] = $this->limit; //默认20 if($this->goods_id) $goods_list_data['goods_id'] = $this->goods_id; if($this->supplier_id) $goods_list_data['supplier_id'] = $this->supplier_id; if($this->name) $goods_list_data['name'] = $this->name; //商品名称 if($this->status) $goods_list_data['status'] = $this->status; //0全部 1审核中 2成功 3失败 $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data); $goodsListInfo = json_decode($goodsListInfo,true); if($goodsListInfo['code'] != 0){ $code = 1;//失败 return $this->outPutData($code,$goodsListInfo['msg']); }else{ return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']); } } //转单详情 public function purchaseOrderInfo($order_id, $supplier_id) { // $order_id = explode(',', $order_id); // $cloud_order_id = $order_id; // $cache = \Yii::$app->cache->get('cloud_supplier_cache_token_' . $supplier_id); // if ($cache) { // $params = json_decode($cache, true); // //3天刷新token // if (time() - $params['time'] < (3 * 24 * 3600) ) { // //return $params['access_token']; // $token = $params['access_token']; // } else { // $supplier = Supplier::findOne($supplier_id); // $response = get_cloud_token($supplier->name, $supplier->password); // $token = ''; // if ($response['code'] == 0 && $response['taken']) { // $token = $response['taken']; // } // } // } else { // $supplier = Supplier::findOne($supplier_id); // $response = get_cloud_token($supplier->name, $supplier->password); // $token = ''; // if ($response['code'] == 0 && $response['taken']) { // $token = $response['taken']; // } // } $token = get_supplier_token(0, $supplier_id); $data = []; $fields = json_decode($this->fields, true); $search = json_decode($this->search, true); $supplier_purchase_order_list_url = "/cloud/supplier/supplierPurchaseOrderList"; $supplier_purchase_order_list_data = []; $supplier_purchase_order_list_data['access_token'] = $token; //获取供货商的token信息 $supplier_purchase_order_list_data['order_id'] = (string)$order_id; //默认为 1 $supplier_purchase_order_list_data['order_type'] = $this->order_type; $supplier_purchase_order_list_data['start_time'] = (int)strtotime($search['start_time']); $supplier_purchase_order_list_data['end_time'] = (int)strtotime($search['end_time']); $supplier_purchase_order_list_data['order_no'] = $search['order_no']; $supplier_purchase_order_list_data['mobile'] = $search['mobile']; $supplier_purchase_order_list_data['user_name'] = $search['user_name']; $supplier_purchase_order_list_data['status'] = $search['status']; $supplier_purchase_order_list_data['export'] = 1; $supplierPurchaseOrderListInfo = cloud_post($this->domain.$supplier_purchase_order_list_url,$supplier_purchase_order_list_data); $supplierPurchaseOrderListInfo = json_decode($supplierPurchaseOrderListInfo,true); if($supplierPurchaseOrderListInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierPurchaseOrderListInfo['msg']); }else{ $order_list = $supplierPurchaseOrderListInfo['data']; $goods = []; foreach ($order_list['list'] as $item) { foreach ($item['goods_list'] as $goods_item) { $attr = ''; if ($goods_item['attr']['attr_list']) { foreach ($goods_item['attr']['attr_list'] as $attr_item) { $attr .= $attr_item['attr_group_name'] . ':' . $attr_item['attr_name'] . ';'; } } else { foreach ($goods_item['attr'] as $attr_item) { $attr .= $attr_item['attr_group_name'] . ':' . $attr_item['attr_name'] . ';'; } } $goods[] = [ 'order_no' => $item['order_no'], //订单编号 'nickname' => $item['name'], //下单用户 'good_name' => $goods_item['name'],//商品名称 'attr' => $attr, //商品规格 'good_num' => $goods_item['num'],//商品数量 'goods_no' => $goods_item['goods_no'],//货号 'name' => $item['name'],//下单人 'mobile' => $item['mobile'],//手机号 'address' => $item['address'],//地址 'cost_price' => $item['goods_price'],//成本价 'total_price' => $item['goods_price'],//总价 'pay_price' => $item['goods_price'], //支付价 'content' => $item['content'],//商家留言 'apply_delete' => ((int)$item['is_refund'] == 1 ? '取消申请订单' : '未取消订单'),//申请状态 'send_time' => !empty($item['send_time']) ? date('Y-m-d H:i:s', $item['send_time']) : '', //发货时间 'merchant_remark' => $item['seller_desc'],//商家留言 'created_at' => !empty($item['pay_time']) ? date('Y-m-d H:i:s', $item['pay_time']) : '',//下单时间 'pay_type' => '线上支付',//支付类型 支付方式:1:微信支付,2:货到付款,3:余额支付,4:支付宝,5:抖音支付,6:线下支付 'trade_status' => $item['status'],//订单状态 订单状态,-1:默认,0:待发货,1:已取消,2:已发货,3:已确认 'pay_time' => !empty($item['pay_time']) ? date('Y-m-d H:i:s', $item['pay_time']) : ''//支付时间 ]; } } } foreach ($goods as $index => &$item) { foreach ($item as $i => $e) { foreach ($fields as $f => $f_e) { $open = true; if ($f === $i) { $open = false; $item[$f_e] = $e; } if ($open) { unset($item[$i]); } } } } $writer = SimpleExcelWriter::streamDownload(time() . '.xlsx') ->addRows($goods)->toBrowser(); // Export::order_3($goods, $fields); } //获取商品规则列表 public function goodsSaleRulesList(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $goods_list_url = "/cloud/supplier/getGoodsSaleRulesList"; $goods_list_data = []; $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息 $goods_list_data['page'] = $this->page; //默认为 1 $goods_list_data['limit'] = $this->limit; //默认20 if($this->name) $goods_list_data['name'] = $this->name; //商品名称 if($this->status !== null && $this->status !== '') $goods_list_data['status'] = $this->status; //0全部 1审核中 2成功 3失败 $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data); $goodsListInfo = json_decode($goodsListInfo,true); if($goodsListInfo['code'] != 0){ $code = 1;//失败 return $this->outPutData($code,$goodsListInfo['msg']); }else{ return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']); } } //保存商品规则 public function goodsSaleRulesSave(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $goods_list_url = "/cloud/supplier/setGoodsSaleRules"; $goods_list_data = []; $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息 $goods_list_data['name'] = $this->name; //默认为 1 $goods_list_data['area'] = $this->area; //默认20 $goods_list_data['status'] = $this->status; //默认20 if($this->id) $goods_list_data['id'] = $this->id; $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data); $goodsListInfo = json_decode($goodsListInfo,true); if($goodsListInfo['code'] != 0){ $code = 1;//失败 return $this->outPutData($code,$goodsListInfo['msg']); }else{ return $this->outPutData($goodsListInfo['code'],"操作成功",$goodsListInfo['data']); } } //修改商品规则状态 public function setGoodsSaleRulesStatus(){ if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $goods_list_url = "/cloud/supplier/setGoodsSaleRulesStatus"; $goods_list_data = []; $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息 $goods_list_data['status'] = $this->status; $goods_list_data['id'] = $this->id; $goods_list_data['ids'] = $this->ids; $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data); $goodsListInfo = json_decode($goodsListInfo,true); if($goodsListInfo['code'] != 0){ $code = 1;//失败 return $this->outPutData($code,$goodsListInfo['msg']); }else{ return $this->outPutData($goodsListInfo['code'],"操作成功",$goodsListInfo['data']); } } public function agentOrderGroupList() { try { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $admin = get_admin(); $goods_list_data = []; $goods_list_url = "/cloud/supplier/getAgentOrderGroup"; $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息 if ($admin->type === Admin::ADMIN_TYPE_FRONT_AGENT || $admin->type === 'admin') { if ($admin->type === 'admin') { $cloud_supplier_id = Supplier::find()->where(['is_delete' => 0])->select('cloud_supplier_id')->column(); } else { $supplier_id = AgentFrontBind::find()->where(['front_agent_admin_id' => $admin->id, 'type' => 0, 'status' => 1, 'is_delete' => 0]) ->select('type_id')->column(); $cloud_supplier_id = Supplier::find()->where(['id' => $supplier_id, 'is_delete' => 0])->select('cloud_supplier_id')->column(); } $goods_list_url = "/cloud/user/getAgentOrderGroup"; $goods_list_data['access_token'] = get_platform_token(); if ($this->supplier_name) { $goods_list_data['supplier_name'] = $this->supplier_name; } $goods_list_data['supplier_id'] = implode(',', $cloud_supplier_id); } $goods_list_data['status'] = $this->status; $goods_list_data['goods_name'] = $this->goods_name; $goods_list_data['type'] = $this->type; $goods_list_data['page'] = $this->page; //默认为 1 $goods_list_data['limit'] = $this->limit; //默认20 $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data); $goodsListInfo = json_decode($goodsListInfo,true); if($goodsListInfo['code'] != 0){ throw new \Exception($goodsListInfo['msg']); }else{ if (!empty($goodsListInfo['data'])) { foreach ($goodsListInfo['data']['data'] as &$data) { $admin_id = $data['admin_id']; $admin = Admin::findOne(['id' => $admin_id]); $district = District::find()->where(['id' => [$admin->province_id, $admin->city_id, $admin->district_id]])->select('name')->column(); $data['admin_name'] = $admin->name; $data['admin_tel'] = $admin->mobile; $data['admin_address'] = implode('/', $district) . ($admin->address ?: ''); if (!empty($data['platform_order_no'])) { $data['mch_order_no'] = Order::findOne($data['platform_order_no'])->order_no; } else { $data['mch_order_no'] = PurchaseOrder::findOne(['cloud_order_id' => $data['order_id']])->order_no; } $data['md_info'] = null; if ($data['md_id'] > 0) { $md_info = Md::findOne($data['md_id']); $data['md_info'] = [ 'logo' => $md_info->cover_url ?? '', 'name' => $md_info->name ?? '', 'tel' => $md_info->mobile ?? '', ]; } if (isset($data['store']['user_id'])) { $store_cloud = StoreCloud::findOne(['cloud_user_id' => $data['store']['user_id'], 'is_delete' => 0]); if ($store_cloud) { $store = Store::findOne($store_cloud->store_id); if ($store) { $data['store'] = [ 'name' => $store->name, 'tel' => $store->contact_tel ?: $store_cloud->tel , 'logo' => $store->logo, ]; } } } } } return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']); } } catch (\Exception $e) { return $this->outPutData(1, $e->getMessage()); } } public function agentOrderDistribution() { try { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $goods_list_url = "/cloud/supplier/agentOrderDistribution"; $goods_list_data = []; $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息 $goods_list_data['start_time'] = $this->start_time; $goods_list_data['end_time'] = $this->end_time; $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data); $goodsListInfo = json_decode($goodsListInfo,true); if($goodsListInfo['code'] != 0){ throw new \Exception($goodsListInfo['msg']); }else{ return $this->outPutData($goodsListInfo['code'],"获取成功"); } } catch (\Exception $e) { return $this->outPutData(1, $e->getMessage()); } } public function agentOrderDistributionList($id = 0, $status = 0) { try { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $goods_list_url = "/cloud/supplier/agentOrderDistributionList"; $goods_list_data = []; $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息 $admin = get_admin(); if ($admin->type === 'admin' || $admin->type === Admin::ADMIN_TYPE_FRONT_AGENT) { $goods_list_url = "/cloud/user/agentOrderDistributionList"; $goods_list_data['access_token'] = get_platform_token(); $goods_list_data['admin_id'] = $admin->id; } $goods_list_data['status'] = $status ?: $this->status; $goods_list_data['id'] = $id ?: $this->id; if ($this->order_no) { $goods_list_data['order_no'] = $this->order_no; } if ($this->sorting_start_time) { $goods_list_data['sorting_start_time'] = $this->sorting_start_time; } if ($this->sorting_end_time) { $goods_list_data['sorting_end_time'] = $this->sorting_end_time; } if ($this->start_time) { $goods_list_data['start_time'] = $this->start_time; } if ($this->end_time) { $goods_list_data['end_time'] = $this->end_time; } $goods_list_data['goods_name'] = $this->goods_name; $goods_list_data['page'] = $this->page; //默认为 1 $goods_list_data['limit'] = $this->limit; //默认20 $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data); $goodsListInfo = json_decode($goodsListInfo,true); if($goodsListInfo['code'] != 0){ throw new \Exception($goodsListInfo['msg']); }else{ $generator = new BarcodeGeneratorJPG(); if (!empty($goodsListInfo['data'])) { foreach ($goodsListInfo['data']['data'] as &$data) { $admin_id = $data['admin_id']; $admin = Admin::findOne(['id' => $admin_id]); $district = District::find()->where(['id' => [$admin->province_id, $admin->city_id, $admin->district_id]])->select('name')->column(); $data['admin_name'] = $admin->name; $data['admin_tel'] = $admin->mobile; $data['admin_address'] = implode('/', $district) . ($admin->address ?: ''); $data['goods_num'] = 0; foreach ($data['mch_goods'] as &$mch_goods) { $cloud_store_id = $mch_goods['store_id']; $store_cloud = StoreCloud::findOne(['cloud_store_id' => $cloud_store_id, 'is_delete' => 0]); if ($store_cloud) { $store = Store::findOne($store_cloud->store_id); $mch_goods['store_name'] = $store->name; } foreach ($mch_goods['mch_order'] as &$mch_order_item) { $md_id = $mch_order_item['md_id']; $md_info = Md::findOne($md_id); $mch_order_item['md_name'] = $md_info->name ?? ($store->name ?? ''); $mch_order_item['md_mobile'] = $md_info->mobile ?? ''; $mch_order_item['goods_num'] += array_sum(array_column($mch_order_item['md_order'], 'goods_num')); } $data['goods_num'] += array_sum(array_column($mch_goods['mch_order'], 'goods_num')); } foreach ($data['goods'] as &$goods_item) { $barcode = $generator->getBarcode($goods_item['goods_no'], $generator::TYPE_CODE_128, 2, 30); $file_name = md5($goods_item['goods_no'] . '_cloud_goods_no_barcode'). '.jpg'; $code_path = \Yii::$app->runtimePath . '/image/' . $file_name; $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $file_name . '?v=' . time()); // 创建一个图像资源 $image = imagecreatefromstring($barcode); // 定义颜色 $black = imagecolorallocate($image, 0, 0, 0); $white = imagecolorallocate($image, 255, 255, 255); // 获取图像的宽度和高度 $imageWidth = imagesx($image); $imageHeight = imagesy($image); // 计算文本的位置 $fontSize = 4; // 字体大小 $textWidth = imagefontwidth($fontSize) * strlen($goods_item['goods_no']); $textX = ($imageWidth - $textWidth) / 2; $textY = $imageHeight + 5; // 文本在条形码下方的位置 // 创建一个新的图像,高度增加以容纳文本 $newImageHeight = $imageHeight + 20; // 增加高度以容纳文本 $newImage = imagecreatetruecolor($imageWidth, $newImageHeight); // 填充背景色 imagefilledrectangle($newImage, 0, 0, $imageWidth, $newImageHeight, $white); // 将条形码图像复制到新图像上 imagecopy($newImage, $image, 0, 0, 0, 0, $imageWidth, $imageHeight); // 在条形码下方添加代码文本 imagestring($newImage, $fontSize, $textX, $textY, $goods_item['goods_no'], $black); // 保存图片到指定路径 imagepng($newImage, $code_path); // 释放内存 imagedestroy($image); imagedestroy($newImage); $goods_item['barcode'] = $pic_url; } } } return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']); } } catch (\Exception $e) { return $this->outPutData(1,$e->getMessage()); } } //更改配送单状态 public function setDistributionStatus() { $t = \Yii::$app->db->beginTransaction(); try { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } //获取平台token $cloud_token = get_supplier_token(); $getGoodsCateUrl = "/cloud/supplier/setDistributionStatus"; $getGoodsCateData['access_token'] = $cloud_token; $getGoodsCateData['ids'] = $this->ids; $getGoodsCateData['status'] = $this->status; $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData); $getGoodsCateInfo = json_decode($getGoodsCateInfo,true); if($getGoodsCateInfo['code'] != 0){ throw new \Exception($getGoodsCateInfo['msg']); } $t->commit(); return $this->outPutData(0, $getGoodsCateInfo['msg']); } catch (\Exception $e) { $t->rollBack(); return $this->outPutData(1, $e->getMessage()); } } //打印配货单 public function exportDistributionInfo() { try { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $goods_list_url = "/cloud/user/agentOrderDistributionList"; if ((int)$this->export === 2) { $goods_list_url = "/cloud/user/getAgentOrderDistributionList"; } $goods_list_data['access_token'] = get_platform_token(); $goods_list_data['id'] = $this->id; $goods_list_data['export'] = $this->export; $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data); $goodsListInfo = json_decode($goodsListInfo,true); if($goodsListInfo['code'] != 0){ throw new \Exception($goodsListInfo['msg']); }else{ if (!empty($goodsListInfo['data'])) { if ((int)$this->export === 1) { $title = []; $data = []; foreach ($goodsListInfo['data']['data'] as $_data) { $admin_id = $_data['admin_id']; $admin = Admin::findOne(['id' => $admin_id]); $_data['admin_name'] = $admin->name; $District = District::find()->where(['id' => [$admin->province_id, $admin->city_id, $admin->district_id]])->select('name')->column(); $address = implode(',', $District); $title = [ [ 'goods_name' => "服务商:" . $_data['admin_name'] . '/' . $admin->mobile, 'goods_attr' => "服务商地址:" . $address . $admin->address, 'goods_num' => "供货商:" . $_data['supplier_name'] ] ]; foreach ($_data['goods'] as $index => $good) { $data[$index]['goods_name'] = $good['goods_name']; // if ((int)$this->export === 2) { // $data[$index]['goods_name'] = $good['goods_name']; // } $attrs = json_decode($good['goods_attr'], true); $attr_str = ''; foreach ($attrs as $attr) { $attr_str .= $attr['attr_group_name'] . ':' . $attr['attr_name'] . ';'; } $data[$index]['goods_attr'] = $attr_str; $data[$index]['goods_num'] = $good['goods_num']; } } $field = [ [ 'goods_name' => '商品', 'goods_attr' => '规格', 'goods_num' => '数量' ] ]; $file_name = '配货单'; } else { $data = []; $_data = $goodsListInfo['data']['data']; // foreach ($goodsListInfo['data']['data'] as $_data) { $admin_id = $_data['admin_id']; $admin = Admin::findOne(['id' => $admin_id]); $_data['admin_name'] = $admin->name; $District = District::find()->where(['id' => [$admin->province_id, $admin->city_id, $admin->district_id]])->select('name')->column(); $address = implode(',', $District); $title = [ [ 'goods_name' => "服务商:" . $_data['admin_name'] . '/' . $admin->mobile, 'goods_attr' => "服务商地址:" . $address . $admin->address, ] ]; $num = 0; foreach ($_data['mch'] as $index => $mch) { if ((int)$mch['type'] === 1) { $mch['mch']['name'] = '采购:' . $mch['address']; } foreach ($mch['goods'] as $goods_index => $goods) { $store_cloud = StoreCloud::findOne(['cloud_user_id' => $mch['mch']['user_id'], 'is_delete' => 0]); $data[$num]['mch_name'] = Store::findOne($store_cloud->store_id)->name;//$goods_index === 0 ? $mch['mch']['name'] : ''; $data[$num]['goods_name'] = $goods['name']; $data[$num]['goods_num'] = $goods['goods_num']; $_attrs = json_decode($goods['goods_attr'], true); $attr = ''; foreach ($_attrs as $_attr) { $attr .= $_attr['attr_group_name'] . ':' . $_attr['attr_name'] . ';'; } $data[$num]['goods_attr'] = $attr; $num++; } // if ((int)$this->export === 2) { // $data[$index]['goods_name'] = $good['goods_name']; // } } $field = [ [ 'mch_name' => '商户信息', 'goods_name' => '商品', 'goods_num' => '数量', 'goods_attr' => '规格' ] ]; // } $file_name = '配送单'; } $data = array_merge($title, $field, $data); SimpleExcelWriter::streamDownload($file_name . time() . '.xlsx') ->noHeaderRow() ->addRows($data) ->toBrowser(); } // return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']); } } catch (\Exception $e) { return $this->outPutData(1, $e->getMessage() . $e->getLine()); } } public function getAgentOrderDistributionList() { try { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $goods_list_url = "/cloud/user/getAgentOrderDistributionList"; $goods_list_data['access_token'] = get_platform_token(); $goods_list_data['id'] = $this->id; $goods_list_data['export'] = $this->export; $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data); $goodsListInfo = json_decode($goodsListInfo,true); if($goodsListInfo['code'] != 0){ throw new \Exception($goodsListInfo['msg']); }else{ if (!empty($goodsListInfo['data'])) { $data = []; $_data = $goodsListInfo['data']['data']; // $order_no = $_data['order_no']; $sorting_time = $_data['order_no']; // foreach ($goodsListInfo['data']['data'] as $_data) { $admin_id = $_data['admin_id']; $admin = Admin::findOne(['id' => $admin_id]); // $_data['admin_name'] = $admin->name; $admin_title = [ 'admin_name' => $admin->name, 'admin_mobile' => $admin->mobile, 'order_no' => $_data['order_no'], 'send_time' => $_data['send_time'] ? date('Y-m-d H:i:s', $_data['send_time']) : '-', 'sorting_time' => $_data['sorting_time'] ? date('Y-m-d H:i:s', $_data['sorting_time']) : '-', ]; $data = $_data['mch']; foreach ($data as $index => &$mch) { $cloud_user_id = $mch['mch']['user_id']; $store_cloud = StoreCloud::findOne(['cloud_user_id' => $cloud_user_id]); if ($store_cloud) { $store_id = $store_cloud->store_id; $store = Store::findOne($store_id); $address = ''; $mobile = ''; if ($store) { $address = Option::get('address', $store_id, 'store', '')['value']; $district = District::find()->where(['id' => [$store->province_id, $store->city_id, $store->district_id]])->select('name')->column(); if ($district) { $district = implode('', $district); $address = $district . $address; } $admin = Admin::findOne(['type' => 'store', 'type_id' => $store->id]); $mobile = $admin->mobile; } $mch['mch'] = [ 'name' => $store->name ?? '-', 'address' => $address, 'mobile' => $mobile ]; foreach ($mch['goods'] as &$goods) { $goods['goods_attr'] = json_decode($goods['goods_attr'], true); } } // if ((int)$mch['type'] === 1) { // $mch['mch']['name'] = '采购:' . $mch['address']; // } // foreach ($mch['goods'] as $goods_index => $goods) { // $store_cloud = StoreCloud::findOne(['cloud_user_id' => $mch['mch']['user_id'], 'is_delete' => 0]); //// $data[$num]['store_name'] = Store::findOne($store_cloud->store_id)->name; // $data[$num]['mch_name'] = Store::findOne($store_cloud->store_id)->name;//$goods_index === 0 ? $mch['mch']['name'] : ''; // $data[$num]['goods_name'] = $goods['name']; // $data[$num]['goods_num'] = $goods['goods_num']; // $_attrs = json_decode($goods['goods_attr'], true); // $attr = ''; // foreach ($_attrs as $_attr) { // $attr .= $_attr['attr_group_name'] . ':' . $_attr['attr_name'] . ';'; // } // $data[$num]['goods_attr'] = $attr; // $num++; // } } return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'goods' => $data, 'admin_title' => $admin_title ] ]; } } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //供货单列表(推送到聚水潭) public function supplierOrderList2Jst($supplier_id = 0, $time = 0){ $cloud_supplier_id = Supplier::find()->where(['id' => $supplier_id, 'is_delete' => 0])->select('cloud_supplier_id')->scalar(); $supplier_order_list_url = "/user/getSupplierOrderList"; $supplier_order_list_data = []; $supplier_order_list_data['time'] = $time; $supplier_order_list_data['supplier_id'] = (int)$cloud_supplier_id; $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data); $supplierOrderListInfo = json_decode($supplierOrderListInfo,true); if($supplierOrderListInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierOrderListInfo['msg']); }else{ return $supplierOrderListInfo; } } //云仓库存列表 public function getCloudPreviewNum(){ //获取平台token $cloud_token = get_supplier_token(); $supplier_order_list_data = []; $supplier_order_list_url = "/cloud/supplier/getCloudPreviewNum"; $supplier_order_list_data['access_token'] = $cloud_token; $supplier_order_list_data['name'] = $this->name; $supplier_order_list_data['mobile'] = $this->mobile; $supplier_order_list_data['page'] = input_params('pageNo') ?: $this->page; //默认为 1 $supplier_order_list_data['limit'] = $this->limit; //默认20 $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data); $supplierOrderListInfo = json_decode($supplierOrderListInfo,true); if($supplierOrderListInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierOrderListInfo['msg']); }else{ if ($supplierOrderListInfo['data']['list']) { foreach ($supplierOrderListInfo['data']['list'] as &$item) { $store_cloud = StoreCloud::findOne(['cloud_store_id' => $item['mch_id'], 'is_delete' => 0]); $item['store_name'] = '-'; if ($store_cloud) { $item['store_name'] = Store::findOne(['id' => $store_cloud->store_id, 'is_delete' => 0])->name ?? '-'; } $user_info = StoreCloud::find()->alias('c') ->leftJoin(['su' => SaasUser::tableName()], 'c.saas_user_id = su.id') ->where(['c.is_delete' => 0, 'c.cloud_store_id' => $item['mch_id']])->select('su.avatar, su.name')->asArray()->one(); if ($user_info) { $item['name'] = $user_info['name'] ?: $item['name']; $item['logo'] = $user_info['avatar'] ?: $item['logo']; } } } return $supplierOrderListInfo; } } //云仓库存列表 public function getCloudPreviewNumInfo(){ //获取平台token $cloud_token = get_supplier_token(); $supplier_order_list_data = []; $supplier_order_list_url = "/cloud/supplier/getCloudPreviewNumInfo"; $supplier_order_list_data['access_token'] = $cloud_token; $supplier_order_list_data['mch_id'] = $this->could_mch_id; $supplier_order_list_data['page'] = input_params('pageNo') ?: $this->page; //默认为 1 $supplier_order_list_data['limit'] = $this->limit; //默认20 $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data); $supplierOrderListInfo = json_decode($supplierOrderListInfo,true); if($supplierOrderListInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierOrderListInfo['msg']); }else{ if ($supplierOrderListInfo['data']['mch_info']) { $mch_id = $supplierOrderListInfo['data']['mch_info']['mch_id']; $store_cloud = StoreCloud::findOne(['cloud_store_id' => $mch_id, 'is_delete' => 0]); $supplierOrderListInfo['data']['mch_info']['store_name'] = '-'; if ($store_cloud) { $supplierOrderListInfo['data']['mch_info']['store_name'] = Store::findOne(['id' => $store_cloud->store_id, 'is_delete' => 0])->name ?? '-'; } $user_info = StoreCloud::find()->alias('c') ->leftJoin(['su' => SaasUser::tableName()], 'c.saas_user_id = su.id') ->where(['c.is_delete' => 0, 'c.cloud_store_id' => $mch_id])->select('su.avatar, su.name')->asArray()->one(); if ($user_info) { $supplierOrderListInfo['data']['mch_info']['name'] = $user_info['name'] ?: $supplierOrderListInfo['data']['mch_info']['name']; $supplierOrderListInfo['data']['mch_info']['logo'] = $user_info['avatar'] ?: $supplierOrderListInfo['data']['mch_info']['logo']; } } return $supplierOrderListInfo; } } //订单改价 public function modifyPrice() { $t = \Yii::$app->db->beginTransaction(); try { //获取平台token $order = PurchaseOrder::findOne(['cloud_order_id' => $this->order_id, 'is_delete' => 0]); if (!$order) { return [ 'code' => 1, 'msg' => '订单不存在' ]; } //判断价格是否小于0 if ((isset($this->pay_price) && $this->pay_price < 0) || (isset($this->express_price) && $this->express_price < 0)) { return [ 'code' => 1, 'msg' => '价格不能小于0' ]; } $money = doubleval($order->pay_price); $express = doubleval($order->express_price); if ($this->goods_id) { $purchase_goods = PurchaseOrderDetail::findOne(['goods_id' => $this->goods_id, 'is_delete' => 0, 'order_id' => $order->id]); //->asArray()->all(); if (!$purchase_goods) { throw new \Exception('商品查询失败'); } $purchaseOrderDetail = PurchaseOrderDetail::findOne($purchase_goods->id); $purchaseOrderDetail->before_update_price = $purchase_goods->total_price; $purchaseOrderDetail->total_price = $this->pay_price; if (!$purchaseOrderDetail->save()) { throw new \Exception(json_encode($purchaseOrderDetail->errors, JSON_UNESCAPED_UNICODE)); } } $goods_total_price = PurchaseOrderDetail::find()->where(['order_id' => $order->id, 'is_delete' => 0])->select('total_price')->sum('total_price'); //计算支付总金额 $express_ = $express; if (isset($this->express_price)) { $express_ = $this->express_price; } $order->pay_price = ($goods_total_price + $express_); if (isset($this->express_price)) { $order->express_price = $this->express_price; } $order->before_update_price = $money; $order->before_update_express = $express; if (!$order->save()) { throw new \Exception(json_encode($order->errors, JSON_UNESCAPED_UNICODE)); } $cloud_token = get_supplier_token(); $supplier_order_modify_price = []; $supplier_order_modify_price_url = "/cloud/supplier/modifyPrice"; $supplier_order_modify_price['access_token'] = $cloud_token; $supplier_order_modify_price['pay_price'] = $this->pay_price; $supplier_order_modify_price['express_price'] = $this->express_price; $supplier_order_modify_price['order_id'] = $this->order_id; $supplier_order_modify_price['goods_id'] = $this->goods_id; $supplier_order_modify_price['send_type'] = $this->send_type; $supplierOrderModifyPriceInfo = cloud_post($this->domain . $supplier_order_modify_price_url, $supplier_order_modify_price); $supplierOrderModifyPriceInfo = json_decode($supplierOrderModifyPriceInfo,true); if($supplierOrderModifyPriceInfo['code'] != 0){ throw new \Exception($supplierOrderModifyPriceInfo['msg'], $supplierOrderModifyPriceInfo['code']); }else{ $t->commit(); return $supplierOrderModifyPriceInfo; } } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //获取平台token public function actionGetSaasToken(){ // $content = Option::get('cloud', 0, 'saas'); // if (!$content['value']){ // return false; // } // $params = json_decode($content['value'],true); // $tokenInfo = get_cloud_token($params['name'],$params['password']); // $params['access_token'] = $tokenInfo['taken']; // Option::set('cloud', json_encode($params), 0, 'saas'); get_platform_token(); } //返回数据 private function outPutData($code,$msg,$data=[]){ $putData = []; $putData['code'] = $code; $putData['msg'] = $msg; if($data) $putData['data'] = $data; return $putData; } //获取网络图片到临时目录 public function saveTempImage($url) { if (strpos($url, 'http') === false) { $url = 'http:' . trim($url); } if (!is_dir(\Yii::$app->runtimePath . '/xlsx')) { mkdir(\Yii::$app->runtimePath . '/xlsx'); } $save_path = \Yii::$app->runtimePath . '/xlsx/' . md5($url) . '.xlsx'; CurlHelper::download($url, $save_path); return $save_path; } }