| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models;
- use app\modules\admin\models\WechatThirdForm;
- use app\utils\Wechat\WechatMini;
- use EasyWeChat\Kernel\BaseClient;
- use app\models\Order;
- use app\models\User;
- use app\models\Goods;
- use app\models\MdGoods;
- use app\models\Express;
- use app\models\DeliveryInfo;
- use app\models\DeliveryMaiyatian;
- use app\models\DeliveryKeloop;
- use app\modules\admin\models\maiyatian\MaiyatianForm;
- use app\modules\admin\models\keloop\KeloopForm;
- use app\models\Option;
- use app\constants\OptionSetting;
- use EasyWeChat\Factory;
- class WastoreForm extends WechatThirdForm
- {
- public static $test = 0;
- public static $confs = [];
- public static function conf($store_id = 0, $refresh = 0) {
- $cacheK = $store_id;
- if(isset(self::$confs[$cacheK]) && !$refresh){
- return self::$confs[$cacheK];
- }
- $conf = json_decode(Option::get(OptionSetting::WASTORE, $store_id, 'store', '{}')['value'], true);
- if(!$conf){
- $conf = [
- 'is_open' => 0,
- ];
- }
- self::$confs[$cacheK] = $conf;
- return $conf;
- }
-
- public static function saveConf($store_id = 0, $config = []) {
- $oldConf = json_decode(Option::get(OptionSetting::WASTORE, $store_id, 'store', '{}')['value'], true);
- $conf = array_merge($oldConf, $config);
- $set = Option::set(OptionSetting::WASTORE, json_encode($conf), $store_id, 'store');
- self::conf($store_id, 1);
- return $set;
- }
- public static function getConf($store_id = 0, $key = '') {
- $config = self::conf($store_id);
- return $config[$key];
- }
- public static function pluginIsOpen($store_id = 0) {
- $is_open = self::getConf($store_id, 'is_open');
- return $is_open;
- }
-
- public function testApp(&$mini_id = 0) {
- $config =[];
- $config['app_id'] = 'wx1ce41243db1e4373';
- $config['secret'] = '6563aceb2ef97e0d2f5b884f11e43544';
- $config['response_type'] = 'array';
- $app = Factory::miniProgram($config);
- $mini_id = 88;
- return $app;
- }
-
- public function wastoreApi($url = '', $store_id = 0, $mini_id = 0, $postData = [], $call = null) {
- try {
- try {
- $app = WechatMini::getWechatConfig($store_id, $mini_id);
- $mini_id = WechatMini::$mini_id;
- } catch (\Throwable $e) {
- \Yii::error([__METHOD__, $e]);
- }
- WastoreForm::$test && $app = $this->testApp($mini_id);
- if (!$app) {
- throw new \Exception('小程序配置获取失败');
- }
- $call && $postData = $call($mini_id);
- $client = new BaseClient($app);
- $result = $client->httpPostJson($url, $postData);
- debug_log([$url, $store_id, $mini_id, $result, $postData], __CLASS__ . '.log');
- if (!empty($result)) {
- if ($result['errcode'] == '0') {
- return [
- 'code' => 0,
- 'msg' => "操作成功",
- 'data' => $result,
- 'postData' => $postData,
- 'url' => $url,
- 'mini_id' => $mini_id,
- ];
- }
- }
- \Yii::error([__METHOD__, $url, $mini_id, $result, $postData]);
- return [
- 'code' => 1,
- 'msg' => "操作失败。" . $result['errmsg'],
- 'data' => $result,
- 'postData' => $postData,
- 'url' => $url,
- 'mini_id' => $mini_id,
- ];
- } catch (\Exception $e) {
- \Yii::error([__METHOD__, $e, $postData, $url, $mini_id]);
- return [
- 'code' => 1,
- 'msg' => "操作失败," . $e->getMessage(),
- 'postData' => $postData,
- 'url' => $url,
- 'mini_id' => $mini_id,
- ];
- }
- }
- //
- public function rid($store_id = 0, $mini_id = 0, $rid = null) {
- $postData = ['rid' => $rid];
- return $this->wastoreApi('cgi-bin/openapi/rid/get', $store_id, $mini_id, $postData);
- }
-
- //门店快送 上传图片
- public function wastoreImgUpload($store_id = 0, $mini_id = 0, $img_url = null, $media = null) {
- try {
- $app = WechatMini::getWechatConfig($store_id, $mini_id);
- $mini_id = WechatMini::$mini_id;
- } catch (\Throwable $e) {
- \Yii::error([__METHOD__, $e]);
- }
- WastoreForm::$test && $app = $this->testApp($mini_id);
- if (!$app) {
- throw new \Exception('小程序配置获取失败');
- }
- $upload_type = $img_url ? 1 : 0;
- $postData = [
- 'resp_type' => 1,
- 'upload_type' => $upload_type,
- ];
- $img_url && $postData['img_url'] = $img_url;
- $media && $postData['media'] = $media;
- $client = new BaseClient($app);
- // $result = $client->imgUpload($img_url ?: $media, 1, $upload_type);
- $result = $client->httpPostJson('shop/img/upload', $postData, $postData);
- if (!empty($result)) {
- if ($result['errcode'] == '0') {
- return $result['img_info']['temp_img_url'];
- }
- }
- throw new \Exception('上传图片失败。' . $result['errcode'] . $result['errmsg'] . json_encode($postData, JSON_UNESCAPED_UNICODE));
- }
- //门店快送查询开通状态
- public function wastoreSceneIsOpen($store_id = 0, $mini_id = 0) {
- $postData = [];
- return $this->wastoreApi('shop/scene/list', $store_id, $mini_id, $postData, function() use ($postData){
- $postData = [
- 'group_id_list' => [9],
- ];
- return $postData;
- });
- }
- //门店快送开通
- public function wastoreSceneOpen($store_id = 0, $mini_id = 0) {
- $postData = [];
- return $this->wastoreApi('shop/scene/enable', $store_id, $mini_id, $postData, function() use ($postData){
- $postData = [
- 'group_id_list' => [9],
- ];
- return $postData;
- });
- }
- //门店的服务类目
- public function wastoreStoreCategoryGet($store_id = 0, $mini_id = 0) {
- $postData = [];
- return $this->wastoreApi('shop/store/category/get', $store_id, $mini_id, $postData);
- }
- //门店快送新建更新门店
- public function wastoreSave($store_id = 0, $mini_id = 0, $md_id = 0, $params = [], $out_store_id = '') {
- $postData = $params['postData'];
- $postData['store_info']['path'] = $postData['store_info']['path'] ?: '/pages/cat/cat';
- $postData['store_info']['cat_id'] = $postData['store_info']['cat_id'] ?: 32;
- $call = function($mini_id) use ($postData, $store_id, $md_id, $out_store_id){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- $out_store_id && $postData['out_store_id'] = $out_store_id;
- if (!empty($postData['store_info']['image'])) {
- $postData['store_info']['image'] = $this->wastoreImgUpload($store_id, $mini_id, $postData['store_info']['image']);
- }else{
- $postData['store_info']['image'] = null;
- }
- if (!empty($postData['store_info']['pics'])) {
- foreach ($postData['store_info']['pics'] as &$item) {
- $item = $this->wastoreImgUpload($store_id, $mini_id, $item);
- }
- }
- if (!empty($postData['store_info']['certificate'])) {
- foreach ($postData['store_info']['certificate'] as &$item) {
- $item = $this->wastoreImgUpload($store_id, $mini_id, $item);
- }
- }
- return $postData;
- };
- if ($out_store_id) {
- $url = 'shop/store/update';
- } else {
- $url = 'shop/store/add';
- }
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送删除门店
- public function wastoreDel($store_id = 0, $mini_id = 0, $md_id = 0, $out_store_id = '') {
- $postData = [];
- $call = function($mini_id) use ($postData, $store_id, $md_id, $out_store_id){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- $out_store_id && $postData['out_store_id'] = $out_store_id;
- return $postData;
- };
- $url = 'shop/store/delete';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送获取门店最新提交信息
- public function wastoreAuditGet($store_id = 0, $mini_id = 0, $md_id = 0, $out_store_id = '') {
- $postData = [];
- $call = function($mini_id) use ($postData, $store_id, $md_id, $out_store_id){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- $out_store_id && $postData['out_store_id'] = $out_store_id;
- return $postData;
- };
- $url = 'shop/store/audit/get';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送获取门店最新过审信息
- public function wastoreGet($store_id = 0, $mini_id = 0, $md_id = 0, $out_store_id = '') {
- $postData = [];
- $call = function($mini_id) use ($postData, $store_id, $md_id, $out_store_id){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- $out_store_id && $postData['out_store_id'] = $out_store_id;
- return $postData;
- };
- $url = 'shop/store/get';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送列出门店最新提交信息
- public function wastoreAuditList($store_id = 0, $mini_id = 0, $page = 1, $pageSize = 100) {
- $postData = [];
- $offset = ($page - 1) * $pageSize;
- $postData['offset'] = (int)$offset;
- $postData['limit'] = (int)$pageSize;
- $url = 'shop/store/audit/list';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData);
- }
- //门店快送列出门店最新过审信息
- public function wastoreList($store_id = 0, $mini_id = 0, $page = 1, $pageSize = 100) {
- $postData = [];
- $offset = ($page - 1) * $pageSize;
- $postData['offset'] = (int)$offset;
- $postData['limit'] = (int)$pageSize;
- $url = 'shop/store/list';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData);
- }
- //门店快送门店设置为休息状态
- public function wastoreClose($store_id = 0, $mini_id = 0, $md_id = 0, $close_time = null, $out_store_id = '') {
- $postData = [];
- $close_time && $postData['close_time'] = $close_time;
- $call = function($mini_id) use ($postData, $store_id, $md_id, $out_store_id){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- $out_store_id && $postData['out_store_id'] = $out_store_id;
- return $postData;
- };
- $url = 'shop/store/close';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送门店设置为营业状态
- public function wastoreOpen($store_id = 0, $mini_id = 0, $md_id = 0, $open_time = null, $out_store_id = '') {
- $postData = [];
- $open_time && $postData['open_time'] = $open_time;
- $call = function($mini_id) use ($postData, $store_id, $md_id, $out_store_id){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- $out_store_id && $postData['out_store_id'] = $out_store_id;
- return $postData;
- };
- $url = 'shop/store/open';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送门店设置为“不展示”
- public function wastoreHide($store_id = 0, $mini_id = 0, $md_id = 0, $out_store_id = '') {
- $postData = [];
- $call = function($mini_id) use ($postData, $store_id, $md_id, $out_store_id){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- $out_store_id && $postData['out_store_id'] = $out_store_id;
- return $postData;
- };
- $url = 'shop/store/hide';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送门店设置为“展示”
- public function wastoreShow($store_id = 0, $mini_id = 0, $md_id = 0, $out_store_id = '') {
- $postData = [];
- $call = function($mini_id) use ($postData, $store_id, $md_id, $out_store_id){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- $out_store_id && $postData['out_store_id'] = $out_store_id;
- return $postData;
- };
- $url = 'shop/store/show';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送添加修改门店配送设置
- public function wastoreDeliverySave($store_id = 0, $mini_id = 0, $md_id = 0, $params = [], $out_store_id = '') {
- $postData = $params['postData'];
- $postData['delivery']['intracity_type'] = 1;
- $call = function($mini_id) use ($postData, $store_id, $md_id, $out_store_id){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- $out_store_id && $postData['out_store_id'] = $out_store_id;
- return $postData;
- };
- $url = 'shop/store/delivery/update';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送获取门店配送设置
- public function wastoreDeliveryGet($store_id = 0, $mini_id = 0, $md_id = 0, $out_store_id = '') {
- $postData = [];
- $call = function($mini_id) use ($postData, $store_id, $md_id, $out_store_id){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- $out_store_id && $postData['out_store_id'] = $out_store_id;
- return $postData;
- };
- $url = 'shop/store/delivery/get';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送获取商品类目详情
- public function wastoreSpuCategory($store_id = 0, $mini_id = 0, $parent_id = null) {
- $postData = [];
- $parent_id && $postData['parent_id'] = $parent_id;
- $url = 'shop/store/spu/category';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData);
- }
- //门店快送添加更新SPU
- public function wastoreSpuAdd($store_id = 0, $mini_id = 0, $goods_id = 0, $params = [], $out_product_id = null, $scene_group = 9) {
- $postData = [];
- if(!empty($postData['scene_group_list'])){
- if(is_array($postData['scene_group_list'])){
- $scene_group = (int)$postData['scene_group_list'][0];
- }else{
- $scene_group = (int)$postData['scene_group_list'];
- }
- }
- $call = function($mini_id) use ($postData, $store_id, $goods_id, $params, $out_product_id, $scene_group){
- $goods = \app\models\Goods::findOne($goods_id);
- $postData['title'] = mb_substr($goods['name'], 0, 60);
- $postData['path'] = '/goods/goods/goods?id=' . $goods_id;
- $postData['head_img'][] = $this->wastoreImgUpload($store_id, $mini_id, $goods['cover_pic']);
- // $pic_list = \app\models\GoodsPic::find()->select('pic_url')->where(['goods_id' => $goods_id, 'is_delete' => 0])->asArray()->all();
- // foreach($pic_list as $item){
- // $item['pic_url'] && $postData['head_img'][] = $this->wastoreImgUpload($store_id, $mini_id, $item['pic_url']);
- // }
- $postData['third_cat_id'] = $params['postData']['third_cat_id'] ?: 102;
- $postData['skus'] = [];
- $goods::skuAttr($goods);
- $attrs = json_decode($goods['attr'], true);
- foreach($attrs as $attr){
- $sku = [];
- $sku['out_sku_id'] = $attr['cyy_skuId'];
- // $attr['pic'] && $sku['thumb_img'] = $this->wastoreImgUpload($store_id, $mini_id, $attr['pic']);
- $sku['sale_price'] = $attr['price'] * 100;
- // $sku['sku_code'] = $attr['no'];
- foreach($attr['attr_list'] as $item){
- $attr_group = $goods->getAttrGroupByAttId($item['attr_id']);
- $attr_group_name = $attr_group ? $attr_group->attr_group_name : null;
- $sku['sku_attrs'][] = [
- 'attr_key' => $attr_group_name,
- 'attr_value' => $item['attr_name'],
- ];
- }
- $postData['skus'][] = $sku;
- }
-
- // $postData = $params['postData'];
- $postData['scene_group_list'] = [$scene_group];
- $postData['out_product_id'] = implode('_', [$store_id, $mini_id, $scene_group, $goods_id]);
- $out_product_id && $postData['out_product_id'] = $out_product_id;
- return $postData;
- };
- $url = 'shop/spu/add';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送删除SPU
- public function wastoreSpuDel($store_id = 0, $mini_id = 0, $goods_id = 0, $out_product_id = null, $scene_group = 9) {
- $postData = [];
- $call = function($mini_id) use ($postData, $store_id, $goods_id, $out_product_id, $scene_group){
- $postData['scene_group_list'] = [$scene_group];
- $postData['out_product_id'] = implode('_', [$store_id, $mini_id, $scene_group, $goods_id]);
- $out_product_id && $postData['out_product_id'] = $out_product_id;
- return $postData;
- };
- $url = 'shop/spu/del';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送上架SPU
- public function wastoreSpuListing($store_id = 0, $mini_id = 0, $goods_id = 0, $out_product_id = null, $scene_group = 9) {
- $postData = [];
- $call = function($mini_id) use ($postData, $store_id, $goods_id, $out_product_id, $scene_group){
- $postData['scene_group_list'] = [$scene_group];
- $postData['out_product_id'] = implode('_', [$store_id, $mini_id, $scene_group, $goods_id]);
- $out_product_id && $postData['out_product_id'] = $out_product_id;
- return $postData;
- };
- $url = 'shop/spu/listing';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送下架SPU
- public function wastoreSpuDelisting($store_id = 0, $mini_id = 0, $goods_id = 0, $out_product_id = null, $scene_group = 9) {
- $postData = [];
- $call = function($mini_id) use ($postData, $store_id, $goods_id, $out_product_id, $scene_group){
- $postData['scene_group_list'] = [$scene_group];
- $postData['out_product_id'] = implode('_', [$store_id, $mini_id, $scene_group, $goods_id]);
- $out_product_id && $postData['out_product_id'] = $out_product_id;
- return $postData;
- };
- $url = 'shop/spu/delisting';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送获取SPU列表
- public function wastoreSpuGetList($store_id = 0, $mini_id = 0, $need_edit_spu = 1, $status = -1, $page = 1, $page_size = 100, $scene_group = 9) {
- $postData = ['scene_group' => $scene_group];
- $postData['need_edit_spu'] = $need_edit_spu;
- (isset($status) && $status > -1) && $postData['status'] = $status;
- $postData['page'] = $page;
- $postData['page_size'] = $page_size;
- $url = 'shop/spu/get_list';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData);
- }
- //门店快送获取SPU详情
- public function wastoreSpuGet($store_id = 0, $mini_id = 0, $need_edit_spu = 1, $goods_id = 0, $out_product_id = null, $scene_group = 9) {
- $postData = ['scene_group' => $scene_group];
- $postData['need_edit_spu'] = $need_edit_spu;
- $call = function($mini_id) use ($postData, $store_id, $goods_id, $out_product_id, $scene_group){
- $postData['out_product_id'] = implode('_', [$store_id, $mini_id, $scene_group, $goods_id]);
- $out_product_id && $postData['out_product_id'] = $out_product_id;
- return $postData;
- };
- $url = 'shop/spu/get';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- // //门店快送添加门店商品
- // public function wastoreStoreSpuAdd($store_id = 0, $mini_id = 0, $md_id = 0, $goods_id = 0, $out_product_id = null, $scene_group = 9) {
- // $postData = [];
- // $call = function($mini_id) use ($postData, $store_id, $md_id, $goods_id, $out_product_id, $scene_group){
- // $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- // $postData['out_spu_id'] = implode('_', [$store_id, $mini_id, $scene_group, $goods_id]);
- // $out_product_id && $postData['out_spu_id_list'][] = $out_product_id;
- // return $postData;
- // };
- // $url = 'shop/store/spu/add';
- // return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- // }
- //门店快送批量添加门店商品
- public function wastoreStoreSpuBatchAdd($store_id = 0, $mini_id = 0, $md_id = 0, $goods_ids = [], $out_product_id = null, $scene_group = 9) {
- $postData = [];
- (!is_array($goods_ids) && $goods_ids) && $goods_ids = explode(',', $goods_ids);
- $call = function($mini_id) use ($postData, $store_id, $md_id, $goods_ids, $out_product_id, $scene_group){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- foreach($goods_ids as $goods_id){
- $postData['out_spu_id_list'][] = implode('_', [$store_id, $mini_id, $scene_group, $goods_id]);
- }
- $out_product_id && $postData['out_spu_id_list'][] = $out_product_id;
- return $postData;
- };
- $url = 'shop/store/spu/batch/add';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- // //门店快送移除门店商品
- // public function wastoreStoreSpuDel($store_id = 0, $mini_id = 0, $md_id = 0, $goods_ids = [], $out_product_id = null, $scene_group = 9) {
- // $postData = [];
- // $call = function($mini_id) use ($postData, $store_id, $md_id, $goods_ids, $out_product_id, $scene_group){
- // $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- // $postData['out_spu_id'] = implode('_', [$store_id, $mini_id, $scene_group, $goods_id]);
- // $out_product_id && $postData['out_spu_id_list'][] = $out_product_id;
- // return $postData;
- // };
- // $url = 'shop/store/spu/delete';
- // return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- // }
- //门店快送批量移除门店商品
- public function wastoreStoreSpuBatchDel($store_id = 0, $mini_id = 0, $md_id = 0, $goods_ids = [], $out_product_id = null, $scene_group = 9) {
- $postData = [];
- (!is_array($goods_ids) && $goods_ids) && $goods_ids = explode(',', $goods_ids);
- $call = function($mini_id) use ($postData, $store_id, $md_id, $goods_ids, $out_product_id, $scene_group){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- foreach($goods_ids as $goods_id){
- $postData['out_spu_id_list'][] = implode('_', [$store_id, $mini_id, $scene_group, $goods_id]);
- }
- $out_product_id && $postData['out_spu_id_list'][] = $out_product_id;
- return $postData;
- };
- $url = 'shop/store/spu/batch/delete';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送查询门店内商品
- public function wastoreStoreSpuList($store_id = 0, $mini_id = 0, $md_id = 0) {
- $postData = [];
- $call = function($mini_id) use ($postData, $store_id, $md_id){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- return $postData;
- };
- $url = 'shop/store/spu/list';
- $res = $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- if(!$res['code'] && !$res['data']['errcode'] && $res['data']['total_num']){
- $goodsList = [];
- $goods_ids = [];
- foreach($res['data']['out_spu_id_list'] as $item){
- $idInfo = explode('_', $item);
- $gid = array_pop($idInfo);
- $goods_ids[$gid] = $item;
- }
-
- $statusList = $this->wastoreStoreSpuBatchGetStatus($store_id, $mini_id, $md_id, array_keys($goods_ids));
- if(!$statusList['code']){
- $status = array_combine(array_column($statusList['data']['spu_list'], 'out_spu_id'), $statusList['data']['spu_list']);
- }
- if($goods_ids){
- $goodsList = Goods::find()->where(['id' => array_keys($goods_ids)])->asArray()->all();
- foreach($goodsList as &$g){
- $g['out_spu_id'] = $goods_ids[$g['id']];
- $g['spu_status'] = 0;
- if($status){
- $g['spu_status'] = $status[$g['out_spu_id']]['status']['sale_status'];
- }
- }
- }
- $res['data']['goodsList'] = $goodsList;
- }
- return $res;
- }
- //门店快送批量上架门店商品
- public function wastoreStoreSpuBatchListing($store_id = 0, $mini_id = 0, $md_id = 0, $goods_ids = [], $out_product_id = null, $scene_group = 9) {
- $postData = [];
- $call = function($mini_id) use ($postData, $store_id, $md_id, $goods_ids, $out_product_id, $scene_group){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- (!is_array($goods_ids) && $goods_ids) && $goods_ids = explode(',', $goods_ids);
- foreach($goods_ids as $goods_id){
- $postData['spu_list'][]['out_spu_id'] = implode('_', [$store_id, $mini_id, $scene_group, $goods_id]);
- }
- $out_product_id && $postData['spu_list'][]['out_spu_id'] = $out_product_id;
- return $postData;
- };
- $url = 'shop/store/spu/batch/listing';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送批量下架门店商品
- public function wastoreStoreSpuBatchDelisting($store_id = 0, $mini_id = 0, $md_id = 0, $goods_ids = [], $out_product_id = null, $scene_group = 9) {
- $postData = [];
- $call = function($mini_id) use ($postData, $store_id, $md_id, $goods_ids, $out_product_id, $scene_group){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- (!is_array($goods_ids) && $goods_ids) && $goods_ids = explode(',', $goods_ids);
- foreach($goods_ids as $goods_id){
- $postData['out_spu_id_list'][] = implode('_', [$store_id, $mini_id, $scene_group, $goods_id]);
- }
- $out_product_id && $postData['out_spu_id_list'][] = $out_product_id;
- return $postData;
- };
- $url = 'shop/store/spu/batch/delisting';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送门店商品批量查询上下架状态
- public function wastoreStoreSpuBatchGetStatus($store_id = 0, $mini_id = 0, $md_id = 0, $goods_ids = [], $out_product_id = null, $scene_group = 9) {
- $postData = [];
- $call = function($mini_id) use ($postData, $store_id, $md_id, $goods_ids, $out_product_id, $scene_group){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- (!is_array($goods_ids) && $goods_ids) && $goods_ids = explode(',', $goods_ids);
- foreach($goods_ids as $goods_id){
- $postData['out_spu_id_list'][] = implode('_', [$store_id, $mini_id, $scene_group, $goods_id]);
- }
- $out_product_id && $postData['out_spu_id_list'][] = $out_product_id;
- return $postData;
- };
- $url = 'shop/store/spu/batch/get/status';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
-
- //门店快送批量更新门店价格
- public function storePriceBatchUpdate($store_id = 0, $mini_id = 0, $md_id = 0, $goods_ids = []) {
- $skuList = [];
- (!is_array($goods_ids) && $goods_ids) && $goods_ids = explode(',', $goods_ids);
- foreach($goods_ids as $goods_id){
- $goods = Goods::findOne($goods_id);
- if($md_id){
- $md_goods = MdGoods::findOne(['goods_id' => $goods_id, 'md_id' => $md_id]);
- if($md_goods){
- $goods = [
- 'id' => $goods_id,
- 'attr' => $md_goods->attr,
- ];
- }
- }
- Goods::skuAttr($goods);
- $attrs = json_decode($goods['attr'], true);
- foreach($attrs as $attr){
- $sku = [];
- $sku['out_sku_id'] = $attr['cyy_skuId'];
- $sku['price_info']['sale_price'] = $attr['price'] * 100;
- $skuList[] = $sku;
- }
- if($skuList){
- foreach(array_chunk($skuList, 100) as $list){
- $res = $this->wastoreStorePriceBatchUpdate($store_id, $mini_id, $md_id, $list);
- if($res['code']){
- return $res;
- }
- }
- }
- }
- return [
- 'code' => 0,
- 'msg' => 'ok',
- ];
- }
- //门店快送门店商品批量设置SKU价格
- public function wastoreStorePriceBatchUpdate($store_id = 0, $mini_id = 0, $md_id = 0, $sku_list = []) {
- $postData = [];
- $postData['sku_list'] = $sku_list;
- $call = function($mini_id) use ($postData, $store_id, $md_id){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- return $postData;
- };
- $url = 'shop/store/price/batch/update';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送门店商品批量获取SKU价格
- public function wastoreStorePriceBatchGet($store_id = 0, $mini_id = 0, $md_id = 0, $out_sku_id_list = []) {
- // $out_sku_id_list = ['cyy_22890_413_427'];
- $postData = [];
- (is_string($out_sku_id_list) && $out_sku_id_list) && $out_sku_id_list = explode(',', $out_sku_id_list);
- $postData['out_sku_id_list'] = $out_sku_id_list;
- $call = function($mini_id) use ($postData, $store_id, $md_id){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- return $postData;
- };
- $url = 'shop/store/price/batch/get';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送门店商品批量设置SKU库存
- public function wastoreStoreStockBatchUpdate($store_id = 0, $mini_id = 0, $md_id = 0, $sku_list = []) {
- $sku_list = [
- [
- "out_sku_id" => 'cyy_22890_413_427',
- "stock" => [
- "stock_quantity" => 1000
- ]
- ]
- ];
- $postData = [];
- $postData['sku_list'] = $sku_list;
- $call = function($mini_id) use ($postData, $store_id, $md_id){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- return $postData;
- };
- $url = 'shop/store/stock/batch/update';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送门店商品批量获取SKU库存
- public function wastoreStoreStockBatchGet($store_id = 0, $mini_id = 0, $md_id = 0, $out_sku_id_list = []) {
- // $out_sku_id_list = ['cyy_22890_413_427'];
- $postData = [];
- (is_string($out_sku_id_list) && $out_sku_id_list) && $out_sku_id_list = explode(',', $out_sku_id_list);
- $postData['out_sku_id_list'] = $out_sku_id_list;
- $call = function($mini_id) use ($postData, $store_id, $md_id){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- return $postData;
- };
- $url = 'shop/store/stock/batch/get';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送提交体验规范审核
- public function wastoreSubmitWxaAudit($store_id = 0, $mini_id = 0) {
- $postData = [];
- $url = 'shop/store/submit_wxa_audit';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData);
- }
- //门店快送列出频道页卡片活动模板
- public function wastoreChannelCardActivityList($store_id = 0, $mini_id = 0, $template_id = 0) {
- $postData = [];
- $template_id && $postData['template_id'] = $template_id;
- $url = 'shop/channel/card/activity/list';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData);
- }
- //门店快送删除频道页卡片活动模板
- public function wastoreChannelCardActivityDel($store_id = 0, $mini_id = 0, $template_id = 0) {
- $postData = [];
- $template_id && $postData['template_id'] = $template_id;
- $url = 'shop/channel/card/activity/delete';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData);
- }
- //门店快送新增更新频道页卡片活动模板
- public function wastoreChannelCardActivityUpsert($store_id = 0, $mini_id = 0, $card_activity = [], $template_id = 0) {
- $postData = [];
- $postData['card_activity'] = $card_activity;
- $template_id && $postData['card_activity']['template_id'] = $template_id;
- $call = function($mini_id) use ($postData, $store_id){
- $postData['card_activity']['activity_image'] = $this->wastoreImgUpload($store_id, $mini_id, $postData['card_activity']['activity_image']);
- return $postData;
- };
- $url = 'shop/channel/card/activity/upsert';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送频道页门店商品卡片活动配置
- public function wastoreChannelSpuUpdate($store_id = 0, $mini_id = 0, $md_id = 0, $goods_ids = [], $card_activity_id = 0, $scene_group = 9) {
- $postData = [];
- $card_activity_id && $postData['card_activity_id'] = $card_activity_id;
- $call = function($mini_id) use ($postData, $store_id, $md_id, $goods_ids, $scene_group){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- (!is_array($goods_ids) && $goods_ids) && $goods_ids = explode(',', $goods_ids);
- foreach($goods_ids as $goods_id){
- $postData['out_spu_id_list'][] = implode('_', [$store_id, $mini_id, $scene_group, $goods_id]);
- }
- return $postData;
- };
- $url = 'shop/channel/spu/update';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- }
- //门店快送查询频道页门店商品卡片活动
- public function wastoreChannelSpuGet($store_id = 0, $mini_id = 0, $md_id = 0) {
- $postData = [];
- $call = function($mini_id) use ($postData, $store_id, $md_id){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- return $postData;
- };
- $url = 'shop/channel/spu/get';
- $res = $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- if(!$res['code']){
- $res['data']['temp'] = $this->wastoreChannelCardActivityList($store_id, $mini_id, $res['data']['card_activity']['template_id']);
- $goodsList = [];
- $goods_ids = [];
- foreach($res['data']['out_spu_id_list'] as $item){
- $idInfo = explode('_', $item);
- $gid = array_pop($idInfo);
- $goods_ids[$gid] = $item;
- }
-
- $statusList = $this->wastoreStoreSpuBatchGetStatus($store_id, $mini_id, $md_id, array_keys($goods_ids));
- if(!$statusList['code']){
- $status = array_combine(array_column($statusList['data']['spu_list'], 'out_spu_id'), $statusList['data']['spu_list']);
- }
- if($goods_ids){
- $goodsList = Goods::find()->where(['id' => array_keys($goods_ids)])->asArray()->all();
- foreach($goodsList as &$g){
- $g['out_spu_id'] = $goods_ids[$g['id']];
- $g['spu_status'] = 0;
- if($status){
- $g['spu_status'] = $status[$g['out_spu_id']]['status']['sale_status'];
- }
- }
- }
- $res['data']['goodsList'] = $goodsList;
- }
- return $res;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //门店快送获取用户实时情况
- public function wastoreSessionGet($store_id = 0, $mini_id = 0, $session_key = '') {
- $postData = ['session_key' => $session_key];
- $url = 'shop/store/session/get';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData);
- }
-
-
-
- public static function afterOrderOtherDataSave($order) {
- try{
- if(!self::pluginIsOpen($order->store_id)){
- return;
- }
- $self = new WastoreForm();
- $self->wastoreShopOrderAdd($order->store_id, 0, $order->md_id, $order);
- } catch (\Exception $e) {
- \Yii::error([__METHOD__, $e]);
- }
- }
-
- public static function afterOrderPrepay($order, $payInfo = ['prepay_id' => '']) {
- try{
- if(!self::pluginIsOpen($order->store_id)){
- return;
- }
- $prepay_id = $payInfo['prepay_id'];
- $self = new WastoreForm();
- $self->wastoreShopOrderUpdatePayInfo($order->store_id, 0, $order, $prepay_id);
- } catch (\Exception $e) {
- \Yii::error([__METHOD__, $e]);
- }
- }
-
- public static function afterOrderPay($order) {
- try{
- $self = new WastoreForm();
- $self->wastoreShopOrderPay($order->store_id, 0, $order);
- } catch (\Exception $e) {
- \Yii::error([__METHOD__, $e]);
- }
- }
-
- public static function afterOrderCancel($order) {
- try{
- $self = new WastoreForm();
- $self->wastoreShopOrderClose($order->store_id, 0, $order);
- } catch (\Exception $e) {
- \Yii::error([__METHOD__, $e]);
- }
- }
-
- public static function afterOrderSend($order) {
- try{
- $self = new WastoreForm();
- $self->wastoreShopDeliverySend($order->store_id, 0, $order);
- self::afterDeliveryChange($order->store_id, $order);
- } catch (\Exception $e) {
- \Yii::error([__METHOD__, $e]);
- }
- }
-
- public static function afterOrderConfirm($order) {
- try{
- $self = new WastoreForm();
- $self->wastoreShopWaybillFinish($order->store_id, 0, $order);
- $self->wastoreShopDeliveryReceive($order->store_id, 0, $order);
- } catch (\Exception $e) {
- \Yii::error([__METHOD__, $e]);
- }
- }
-
- public static function afterOrderSave($insert, $changedAttributes, $order) {
- try{
- if(!self::pluginIsOpen($order->store_id)){
- return;
- }
- //支付订单
- if (($order->is_pay == 1) && ($changedAttributes['is_pay'] != 1)) {
- self::afterOrderPay($order);
- }
- //取消订单
- if (($order->trade_status == Order::ORDER_FLOW_CANCEL) && ($changedAttributes['trade_status'] != Order::ORDER_FLOW_CANCEL)) {
- self::afterOrderCancel($order);
- }
- //发货
- if (($order->trade_status == Order::ORDER_FLOW_SEND) && ($changedAttributes['trade_status'] != Order::ORDER_FLOW_SEND)) {
- self::afterOrderSend($order);
- }
- //发货
- if (($order->trade_status == Order::ORDER_FLOW_CONFIRM) && ($changedAttributes['trade_status'] != Order::ORDER_FLOW_CONFIRM)) {
- self::afterOrderConfirm($order);
- }
- } catch (\Exception $e) {
- \Yii::error([__METHOD__, $e]);
- }
- }
-
- public static function afterDeliveryChange($store_id, $order) {
- try{
- if(!self::pluginIsOpen($store_id)){
- return;
- }
- $self = new self();
- $self->wastoreShopWaybillUpdate($store_id, 0, $order);
- } catch (\Exception $e) {
- \Yii::error([__METHOD__, $e]);
- }
- }
- //门店快送创建订单
- public function wastoreShopOrderAdd($store_id = 0, $mini_id = 0, $md_id = 0, $order = null) {
- if(!is_object($order)){
- $order = Order::findOne($order);
- }
- if(!$cache = cache()->get('wastoreShopOrderAdd' . $order->id)){
- return;
- }
- $postData = [];
- $call = function($mini_id) use ($postData, $store_id, $md_id, $order, $cache){
- $postData['out_store_id'] = implode('_', [$store_id, $mini_id, $md_id]);
- $postData['out_order_id'] = $order->order_no;
- $postData['create_time'] = date('Y-m-d H:i:s', $order->created_at);
- $user = User::findOne($order->user_id);
- $postData['openid'] = $user->wechat_open_id;
- $postData['path'] = 'order/order-detail/order-detail?id=' . $order->id;
- $postData['fund_type'] = 3;
- $postData['trace_id'] = $cache['traceId'];
- $postData['delivery_free'] = $order->is_offline ? true : false;
- if(!$postData['delivery_free']){
- $address = json_decode($order->address_data, true);
- $postData['address_info'] = [
- 'receiver_name' => $order->name,
- 'detailed_address' => $order->address,
- 'tel_number' => $order->mobile,
- 'province' => $address['province'],
- 'city' => $address['city'],
- 'town' => $address['district'],
- ];
- }
- $freight = $order->express_price;
- if($order->is_delivery){
- $deliveryInfo = DeliveryInfo::findOne(['order_no' => $order->order_no, 'is_delete' => 0]);
- $freight = $deliveryInfo['fee'];
- }
- $product_infos = [];
- foreach($order->detail as $ad){
- $scene_group = 9;
- $goods_id = $ad['goods_id'];
- $out_product_id = implode('_', [$store_id, $mini_id, $scene_group, $goods_id]);
- $goods = json_decode($ad['goods_info'], true);
- $skuAttr = Goods::skuAttr($goods, json_decode($ad['attr'], true));
- $product_info = [
- 'out_product_id' => $out_product_id,
- 'out_sku_id' => $skuAttr['cyy_skuId'],
- 'product_cnt' => $ad['num'],
- 'sale_price' => $skuAttr['price'] * 100,
- 'sku_real_price' => $skuAttr['price'] * 100,
- 'title' => $goods['name'],
- 'head_img' => $skuAttr['pic'] ?: $goods['cover_pic'],
- 'path' => 'goods/goods/goods?id=' . $goods_id,
- ];
- $product_infos[] = $product_info;
- }
- $postData['order_detail'] = [
- 'price_info' => [
- 'freight' => $freight * 100,
- 'order_price' => $order->pay_price * 100,
- ],
- 'product_infos' => $product_infos,
- ];
- return $postData;
- };
- $url = 'shop/order/add';
- $res = $this->wastoreApi($url, $store_id, $mini_id, $postData, $call);
- if(!$res['code'] && !$res['data']['errcode']){
- cache()->delete('wastoreShopOrderAdd' . $order->id);
- }
- return $res;
- }
- //门店快送获取订单
- public function wastoreShopOrderGet($store_id = 0, $mini_id = 0, $order = null) {
- if(!is_object($order)){
- $order = Order::findOne($order);
- }
- $postData = [];
- $postData['out_order_id'] = $order->order_no;
- $user = User::findOne($order->user_id);
- $postData['openid'] = $user->wechat_open_id;
- $url = 'shop/order/get';
- return $this->wastoreApi($url, $store_id, $mini_id, $postData);
- }
- //门店快送更新支付信息
- public function wastoreShopOrderUpdatePayInfo($store_id = 0, $mini_id = 0, $order = null, $prepay_id = '', $prepay_time = 0) {
- if(!is_object($order)){
- $order = Order::findOne($order);
- }
- $wastoreOrder = $this->wastoreShopOrderGet($store_id, $mini_id, $order);
- if($wastoreOrder['code'] || $wastoreOrder['data']['errcode'] || empty($wastoreOrder['data']['order'])){
- return;
- }
- $postData = [];
- $postData['out_order_id'] = $order->order_no;
- $user = User::findOne($order->user_id);
- $postData['openid'] = $user->wechat_open_id;
- $postData['pay_info'] = [
- 'prepay_id' => $prepay_id,
- 'prepay_time' => date('Y-m-d H:i:s', $prepay_time ?: time()),
- ];
- $url = 'shop/order/update_pay_info';
- $res = $this->wastoreApi($url, $store_id, $mini_id, $postData);
- return $res;
- }
- //门店快送支付订单
- public function wastoreShopOrderPay($store_id = 0, $mini_id = 0, $order = null) {
- if(!is_object($order)){
- $order = Order::findOne($order);
- }
- if(!$order->is_pay){
- return;
- }
- $wastoreOrder = $this->wastoreShopOrderGet($store_id, $mini_id, $order);
- if($wastoreOrder['code'] || $wastoreOrder['data']['errcode'] || empty($wastoreOrder['data']['order'])){
- return;
- }
- $postData = [];
- $postData['out_order_id'] = $order->order_no;
- $user = User::findOne($order->user_id);
- $postData['openid'] = $user->wechat_open_id;
- $postData['pay_time'] = date('Y-m-d H:i:s', $order->pay_time);
- $pay_method_type = $order->pay_type == Order::PAY_TYPE_WECHAT ? 0 : 99;
- $postData['pay_method_type'] = $pay_method_type;
- $url = 'shop/order/pay';
- $res = $this->wastoreApi($url, $store_id, $mini_id, $postData);
- return $res;
- }
- //门店快送支付订单
- public function wastoreShopOrderClose($store_id = 0, $mini_id = 0, $order = null) {
- if(!is_object($order)){
- $order = Order::findOne($order);
- }
- if(!$order->is_pay){
- return;
- }
- $wastoreOrder = $this->wastoreShopOrderGet($store_id, $mini_id, $order);
- if($wastoreOrder['code'] || $wastoreOrder['data']['errcode'] || empty($wastoreOrder['data']['order'])){
- return;
- }
- $postData = [];
- $postData['out_order_id'] = $order->order_no;
- $user = User::findOne($order->user_id);
- $postData['openid'] = $user->wechat_open_id;
- $postData['close_reason'] = '订单取消.';
- $close_type = $order->is_pay ? 2 : 0;
- $postData['close_type'] = $close_type;
- $url = 'shop/order/close';
- $res = $this->wastoreApi($url, $store_id, $mini_id, $postData);
- return $res;
- }
- //门店快送订单发货
- public function wastoreShopDeliverySend($store_id = 0, $mini_id = 0, $order = null) {
- if(!is_object($order)){
- $order = Order::findOne($order);
- }
- if(!$order->is_pay){
- return;
- }
- $wastoreOrder = $this->wastoreShopOrderGet($store_id, $mini_id, $order);
- if($wastoreOrder['code'] || $wastoreOrder['data']['errcode'] || empty($wastoreOrder['data']['order'])){
- return;
- }
- $postData = [];
- $postData['out_order_id'] = $order->order_no;
- $user = User::findOne($order->user_id);
- $postData['openid'] = $user->wechat_open_id;
- $delivery_id = '';
- $waybill_id = '';
- $delivery_type = 6;
- if($order->is_offline){
- $delivery_type = 4;
- }
- if($order->express_no){
- $delivery_type = 1;
- $waybill_id = $order->express_no;
- $delivery_id = Express::getExpressCode($order->express);
- }
- if($order->is_delivery){
- $delivery_type = 6;
- $delivery_id = 'OTHER';
- $waybill_id = $order->order_no;
- }
- $postData['delivery_list'] = [[
- 'delivery_id' => $delivery_id,
- 'waybill_id' => $waybill_id,
- 'delivery_type' => $delivery_type,
- 'product_info_list' => $wastoreOrder['data']['order']['order_detail']['product_infos'],
- ]];
- $url = 'shop/delivery/send';
- $res = $this->wastoreApi($url, $store_id, $mini_id, $postData);
- return $res;
- }
- //门店快送更新配送状态
- public function wastoreShopWaybillUpdate($store_id = 0, $mini_id = 0, $order = null) {
- if(!is_object($order)){
- $order = Order::findOne($order);
- }
- if(!$order->is_pay){
- return;
- }
- $wastoreOrder = $this->wastoreShopOrderGet($store_id, $mini_id, $order);
- if($wastoreOrder['code'] || $wastoreOrder['data']['errcode'] || empty($wastoreOrder['data']['order'])){
- return;
- }
- $deliveryInfo = DeliveryInfo::findOne(['order_no' => $order->order_no, 'is_delete' => 0]);
- if($deliveryInfo['wechat_delivery_type']){
- return;
- }
- $delivery_state = 40000;
- if($deliveryInfo['is_local']){
- if($deliveryInfo['local_status'] < 2){
- $delivery_state = 20000;
- }
- }
- $deliveryMaiyatian = DeliveryMaiyatian::findOne(['order_no' => $order->order_no, 'store_id' => $store_id]);
- if($deliveryMaiyatian){
- if($deliveryMaiyatian['delivery_status'] != MaiyatianForm::DELIVERY_STATUS_DELIVERING){
- $delivery_state = 20000;
- }
- }
- $deliveryKeloop = DeliveryKeloop::findOne(['order_no' => $order->order_no, 'store_id' => $store_id]);
- if($deliveryKeloop){
- if($deliveryKeloop['delivery_status'] != KeloopForm::DELIVERY_STATUS_DELIVERING){
- $delivery_state = 20000;
- }
- }
- $postData = [];
- $postData['out_order_id'] = $order->order_no;
- $user = User::findOne($order->user_id);
- $postData['openid'] = $user->wechat_open_id;
- $postData['waybill_id'] = $order->order_no;
- $postData['delivery_man_name'] = $deliveryInfo->rider_name;
- $postData['delivery_man_phone'] = $deliveryInfo->rider_mobile;
- $postData['delivery_state'] = $delivery_state;
- $postData['expected_time'] = $order->delivery_time ?: ($order->send_time + 86400 * 5);
- $url = 'shop/waybill/update';
- $res = $this->wastoreApi($url, $store_id, $mini_id, $postData);
- return $res;
- }
- //门店快送配送单已完成
- public function wastoreShopWaybillFinish($store_id = 0, $mini_id = 0, $order = null) {
- if(!is_object($order)){
- $order = Order::findOne($order);
- }
- $postData = [];
- $postData['out_order_id'] = $order->order_no;
- $user = User::findOne($order->user_id);
- $postData['openid'] = $user->wechat_open_id;
- $postData['waybill_id'] = $order->order_no;
- $postData['finish_time'] = time();
- $url = 'shop/waybill/finish';
- $res = $this->wastoreApi($url, $store_id, $mini_id, $postData);
- return $res;
- }
- //门店快送订单已完成
- public function wastoreShopDeliveryReceive($store_id = 0, $mini_id = 0, $order = null) {
- if(!is_object($order)){
- $order = Order::findOne($order);
- }
- $postData = [];
- $postData['out_order_id'] = $order->order_no;
- $user = User::findOne($order->user_id);
- $postData['openid'] = $user->wechat_open_id;
- $url = 'shop/delivery/receive';
- $res = $this->wastoreApi($url, $store_id, $mini_id, $postData);
- return $res;
- }
-
-
-
-
-
- }
|