| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701 |
- <?php
- namespace hd\controllers;
- use biz\shop\classes\ShopExtClass;
- use biz\stock\classes\GoodsStockRecordClass;
- use bizHd\custom\classes\CustomClass;
- use bizHd\goods\classes\CategoryClass;
- use bizHd\goods\classes\GoodsCategoryClass;
- use bizHd\goods\classes\GoodsClass;
- use bizHd\meituan\classes\MtOrderClass;
- use bizHd\order\classes\OrderClass;
- use bizHd\order\classes\OrderGoodsClass;
- use bizHd\order\classes\OrderItemClass;
- use bizHd\order\services\OrderService;
- use bizHd\refund\classes\HdRefundClass;
- use bizHd\refund\services\HdRefundService;
- use bizHd\shop\classes\ShopClass;
- use bizHd\work\classes\WorkClass;
- use common\components\dict;
- use common\components\httpUtil;
- use common\components\mtUtil;
- use common\components\noticeUtil;
- use common\components\oss;
- use common\components\util;
- use Yii;
- use Shishaoqi\MeituanFlashPurchase\Application;
- use yii\helpers\Json;
- class MtController extends PublicController
- {
- public $guestAccess = [];
- //订单完成 ssh 20220928
- public function actionFinishOrder()
- {
- return Json::encode(['data' => 'ok']);
- //error_reporting(E_ALL);
- $post = Yii::$app->request->post();
- $mtOrderId = $post['order_id'] ?? 0;
- $thirdSn = $post['day_seq'] ?? 0;
- //4秒内不允许第三方重复通知
- $cacheKey = 'mt_finish_order_' . $mtOrderId;
- $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (!empty($has)) {
- Yii::info("美团推送完成订单报错,出现重复通知,美团订单id:{$mtOrderId} 美团编号:{$thirdSn}");
- return Json::encode(['data' => 'ok']);
- }
- Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 4, 'has']);
- // 无数据过来时,是美团对接口进行存活试探,请保留此段代码,好让请求在此被中断返回
- if (empty($post)) {
- return Json::encode(['data' => 'ok']);
- }
- Yii::info('confirmOrderData: ' . json_encode($post));
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $shopId = $post['app_poi_code'] ?? '';
- $shop = ShopClass::getById($shopId, true);
- if (empty($shop)) {
- noticeUtil::push("美团推送完成订单报错,没有找到门店,美团订单id:{$mtOrderId} 美团编号:{$thirdSn}", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
- if (empty($shopExt)) {
- noticeUtil::push("美团推送完成订单报错,没有找到门店拓展信息,美团订单id:{$mtOrderId} 美团编号:{$thirdSn}", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $mainId = $shop->mainId ?? 0;
- $sjId = $shop->sjId ?? 0;
- $customId = $shop->defaultCustomId ?? 0;
- if (empty($customId)) {
- noticeUtil::push("美团推送完成订单报错,没有找到客户哦,美团订单id:{$mtOrderId} 美团编号:{$thirdSn}", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $custom = CustomClass::getById($customId);
- if (empty($custom)) {
- noticeUtil::push("美团推送完成订单报错,没有找到客户,美团订单id:{$mtOrderId} 美团编号:{$thirdSn}", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $order = OrderClass::getByCondition(['fromType' => 4, 'thirdOrderId' => $mtOrderId], true);
- if (empty($order)) {
- noticeUtil::push("美团推送完成订单报错,没有找到客户,美团订单id:{$mtOrderId} 美团编号:{$thirdSn}", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- if ($order->status != 2 || $order->status != 3) {
- noticeUtil::push("美团推送完成订单报错,订单不是待完成订单,美团订单id:{$mtOrderId} 美团编号:{$thirdSn}", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- //开发中,待完成
- $transaction->commit();
- return Json::encode(['data' => 'ok']);
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- noticeUtil::push("确认订单报错了,美团订单id:{$mtOrderId} 美团编号:{$thirdSn},错误信息:{$msg}", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- }
- public function actionGoodsAdd()
- {
- return Json::encode(['data' => 'ok']);
- $post = Yii::$app->request->post();
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- if (isset($post['retail_data']) == false) {
- //noticeUtil::push("..美团添加商品,通知我们时出错了,没有获取到请求的具体信息", '15280215347');
- return Json::encode(['data' => 'ok']);
- Yii::$app->end();
- }
- $retailData = $post['retail_data'];
- $retail = urldecode(urldecode($retailData));
- $info = json_decode($retail);
- $obj = $info[0] ?? null;
- $shopId = $obj->app_poi_code ?? 0;
- $shop = ShopClass::getById($shopId, true);
- if (empty($shop)) {
- noticeUtil::push("..美团添加商品,通知我们时出错了,没有找到门店", '15280215347');
- //return Json::encode(['data' => 'ok']);
- Yii::$app->end();
- }
- $sjId = $shop->sjId ?? 0;
- $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
- if (empty($ext)) {
- noticeUtil::push("..美团添加商品,通知我们时出错了,没有找到门店拓展信息", '15280215347');
- //return Json::encode(['data' => 'ok']);
- Yii::$app->end();
- }
- $mainId = $shop->mainId ?? 0;
- if (empty($mainId)) {
- noticeUtil::push("..美团添加商品,通知我们时出错了,没有main信息24", '15280215347');
- //return Json::encode(['data' => 'ok']);
- Yii::$app->end();
- }
- $mtCategory = CategoryClass::getByCondition(['mainId' => $mainId, 'style' => 1], true);
- if (empty($mtCategory)) {
- $mtCategory = CategoryClass::add(['style' => 1, 'categoryName' => '美团', 'mainId' => $mainId, 'sjId' => $sjId], true);
- }
- $catId = $mtCategory->id ?? 0;
- if (empty($catId)) {
- noticeUtil::push("..美团添加商品,通知我们时出错了,没有美团的分类id", '15280215347');
- //return Json::encode(['data' => 'ok']);
- Yii::$app->end();
- }
- $config = dict::getDict('mtConfig');
- $app = new Application($config);
- $accessToken = mtUtil::getAccessToken($ext);
- $appSpuCode = $obj->app_spu_code ?? '';
- $hasGoods = GoodsClass::getByCondition(['mainId' => $mainId, 'spu' => $appSpuCode], true);
- if (!empty($hasGoods)) {
- noticeUtil::push("..美团添加商品,通知我们时,发现已经有这个商品了,mainId:{$mainId} spu:{$appSpuCode}", '15280215347');
- //return Json::encode(['data' => 'ok']);
- Yii::$app->end();
- }
- $params = ['app_poi_code' => (string)$shopId, 'app_spu_code' => $appSpuCode, 'access_token' => $accessToken];
- $goodsInfo = $app->retail->getDetail($params);
- Yii::info('获取商品详情:' . $goodsInfo . ' ' . json_encode($params));
- $goodsInfo = json_decode($goodsInfo, true);
- if (isset($goodsInfo['error'])) {
- noticeUtil::push("..美团添加商品,通知我们时出错了,没有找到商品!", '15280215347');
- //return Json::encode(['data' => 'ok']);
- Yii::$app->end();
- }
- $imgString = $goodsInfo['data']['picture'] ?? '';
- if (empty($imgString)) {
- noticeUtil::push("..美团添加商品,通知我们时出错了,没有商品图片...", '15280215347');
- //return Json::encode(['data' => 'ok']);
- Yii::$app->end();
- }
- noticeUtil::push("..美团添加商品,通知我们,商品图片:" . $imgString);
- $goodsName = $goodsInfo['data']['name'] ?? '';
- $goodsPrice = $goodsInfo['data']['price'] ?? '';
- $description = $goodsInfo['data']['description'] ?? '';
- $sh = strstr($description, '【鲜花】') !== false ? 1 : 0;
- $shopImg = [];
- $cover = '';
- $imgArr = explode(',', $imgString);
- if (!empty($imgArr)) {
- foreach ($imgArr as $imgUrl) {
- $shortUrl = httpUtil::downloadRemoteImg($sjId, $shopId, $imgUrl);
- $shopImg[] = $shortUrl;
- if ($cover == '') {
- $cover = $shortUrl;
- }
- }
- }
- $catIds = [$catId];
- $addData = [
- 'name' => $goodsName,
- 'flower' => 1,
- 'property' => 0,
- 'price' => $goodsPrice,
- 'sjId' => $sjId,
- 'mainId' => $mainId,
- 'shopId' => $shopId,
- 'status' => 0,
- 'delStatus' => 0,
- 'shopImg' => $shopImg,
- 'catIds' => $catIds,
- 'cover' => $cover,
- 'spu' => $appSpuCode,
- 'sh' => $sh,
- ];
- GoodsClass::addGoods($addData);
- $transaction->commit();
- return Json::encode(['data' => 'ok']);
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- noticeUtil::push("..美团添加商品,通知我们时出错了,错误信息:{$msg}", '15280215347');
- //return Json::encode(['data' => 'ok']);
- Yii::$app->end();
- }
- }
- //删除商品 ssh 20220914
- public function actionGoodsDel()
- {
- return Json::encode(['data' => 'ok']);
- $post = Yii::$app->request->post();
- if (isset($post['retail_data']) == false) {
- //noticeUtil::push("美团删除商品,通知我们时出错了,没有获取到相应信息", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $retailData = $post['retail_data'];
- $retail = urldecode(urldecode($retailData));
- $info = json_decode($retail);
- $obj = $info[0] ?? null;
- $shopId = $obj->app_poi_code ?? 0;
- $shop = ShopClass::getById($shopId, true);
- if (empty($shop)) {
- noticeUtil::push("美团删除商品,通知我们时出错了,没有找到门店", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $sjId = $shop->sjId ?? 0;
- $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
- if (empty($ext)) {
- noticeUtil::push("美团删除商品,通知我们时出错了,没有找到门店拓展信息", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $mainId = $shop->mainId ?? 0;
- if (empty($mainId)) {
- noticeUtil::push("美团删除商品,通知我们时出错了,没有main信息25", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $mtCategory = CategoryClass::getByCondition(['mainId' => $mainId, 'style' => 1], true);
- if (empty($mtCategory)) {
- $mtCategory = CategoryClass::add(['style' => 1, 'categoryName' => '美团', 'mainId' => $mainId, 'sjId' => $sjId], true);
- }
- $catId = $mtCategory->id ?? 0;
- if (empty($catId)) {
- noticeUtil::push("美团删除商品,通知我们时出错了,没有美团的分类id", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $appSpuCode = $obj->app_spu_code ?? '';
- $hasGoods = GoodsClass::getByCondition(['mainId' => $mainId, 'spu' => $appSpuCode], true);
- if (empty($hasGoods)) {
- return Json::encode(['data' => 'ok']);
- }
- $hasGoods->delStatus = 1;
- $hasGoods->save();
- $goodsId = $hasGoods->id ?? 0;
- GoodsCategoryClass::updateByCondition(['gId' => $goodsId], ['delStatus' => 1]);
- return Json::encode(['data' => 'ok']);
- }
- //修改商品 ssh 20220914
- public function actionGoodsUpdate()
- {
- return Json::encode(['data' => 'ok']);
- $post = Yii::$app->request->post();
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- if (isset($post['retail_data']) == false) {
- //noticeUtil::push("美团修改商品,通知我们时出错了,没有获取到相应信息", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $retailData = $post['retail_data'];
- $retail = urldecode(urldecode($retailData));
- $info = json_decode($retail);
- $obj = $info[0] ?? null;
- $shopId = $obj->app_poi_code ?? 0;
- $shop = ShopClass::getById($shopId, true);
- if (empty($shop)) {
- noticeUtil::push("美团修改商品,通知我们时出错了,没有找到门店", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $sjId = $shop->sjId ?? 0;
- $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
- if (empty($ext)) {
- noticeUtil::push("美团修改商品,通知我们时出错了,没有找到门店拓展信息", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $mainId = $shop->mainId ?? 0;
- if (empty($mainId)) {
- noticeUtil::push("美团修改商品,通知我们时出错了,没有main信息26", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $mtCategory = CategoryClass::getByCondition(['mainId' => $mainId, 'style' => 1], true);
- if (empty($mtCategory)) {
- $mtCategory = CategoryClass::add(['style' => 1, 'categoryName' => '美团', 'mainId' => $mainId, 'sjId' => $sjId], true);
- }
- $catId = $mtCategory->id ?? 0;
- if (empty($catId)) {
- noticeUtil::push("美团修改商品,通知我们时出错了,没有美团的分类id", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $config = dict::getDict('mtConfig');
- $app = new Application($config);
- $accessToken = mtUtil::getAccessToken($ext);
- $appSpuCode = $obj->app_spu_code ?? '';
- $hasGoods = GoodsClass::getByCondition(['mainId' => $mainId, 'spu' => $appSpuCode], true);
- if (empty($hasGoods)) {
- noticeUtil::push("美团修改商品,通知我们时,没有发现这个商品,mainId:{$mainId} spu:{$appSpuCode}", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $hasGoodsId = $hasGoods->id ?? 0;
- $params = ['app_poi_code' => $shopId, 'app_spu_code' => $appSpuCode, 'access_token' => $accessToken];
- $goodsInfo = $app->retail->getDetail($params);
- Yii::info('获取商品详情:' . $goodsInfo . ' ' . json_encode($params));
- $goodsInfo = json_decode($goodsInfo, true);
- if (isset($goodsInfo['error'])) {
- noticeUtil::push("美团修改商品,通知我们时出错了,没有找到商品图片", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $imgString = $goodsInfo['data']['picture'] ?? '';
- if (empty($imgString)) {
- noticeUtil::push("美团修改商品,通知我们时出错了,没有商品图片...", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $goodsName = $goodsInfo['data']['name'] ?? '';
- $goodsPrice = $goodsInfo['data']['price'] ?? '';
- $description = $goodsInfo['data']['description'] ?? '';
- $sh = strstr($description, '【鲜花】') !== false ? 1 : 0;
- $currentStr = md5($goodsName . '_' . $goodsPrice . '_' . $description . '_' . $sh . '_' . $imgString);
- $cacheKey = 'mt_goods_id_' . $hasGoodsId;
- $cacheStr = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if ($cacheStr == $currentStr) {
- //商品没有更新
- return Json::encode(['data' => 'ok']);
- } else {
- Yii::$app->redis->executeCommand('SET', [$cacheKey, $currentStr]);
- }
- noticeUtil::push("美团修改商品,通知我们,商品图片:" . $imgString);
- $shopImg = [];
- $cover = '';
- $imgArr = explode(',', $imgString);
- if (!empty($imgArr)) {
- foreach ($imgArr as $imgUrl) {
- $shortUrl = httpUtil::downloadRemoteImg($sjId, $shopId, $imgUrl);
- $shopImg[] = $shortUrl;
- if ($cover == '') {
- $cover = $shortUrl;
- }
- }
- }
- $hasGoods->price = $goodsPrice;
- $hasGoods->name = $goodsName;
- $hasGoods->cover = $cover;
- $hasGoods->sh = $sh;
- $hasGoods->shopImg = json_encode($shopImg);
- $hasGoods->save();
- $transaction->commit();
- return Json::encode(['data' => 'ok']);
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- noticeUtil::push("美团修改商品,通知我们时出错了,错误信息:{$msg}", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- }
- //已确认订单通知
- public function actionConfirmOrder()
- {
- return Json::encode(['data' => 'ok']);
- //error_reporting(E_ALL);
- $post = Yii::$app->request->post();
- $mtOrderId = $post['order_id'] ?? 0;
- $thirdSn = $post['day_seq'] ?? 0;
- //4秒内不允许第三方重复通知
- $cacheKey = 'mt_confirm_order_' . $mtOrderId;
- $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (!empty($has)) {
- Yii::info("美团已确认订单通知,出现重复通知,美团订单id:{$mtOrderId} 美团编号:{$thirdSn}");
- return Json::encode(['data' => 'ok']);
- }
- Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 4, 'has']);
- // 无数据过来时,是美团对接口进行存活试探,请保留此段代码,好让请求在此被中断返回
- if (empty($post)) {
- return Json::encode(['data' => 'ok']);
- }
- Yii::info('confirmOrderData: ' . json_encode($post));
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $shopId = $post['app_poi_code'] ?? '';
- $shop = ShopClass::getById($shopId, true);
- if (empty($shop)) {
- noticeUtil::push("美团确认订单报错,没有找到门店,美团订单id:{$mtOrderId} 美团编号:{$thirdSn}", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
- if (empty($shopExt)) {
- noticeUtil::push("美团确认订单报错,没有找到门店拓展信息,美团订单id:{$mtOrderId} 美团编号:{$thirdSn}", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $mainId = $shop->mainId ?? 0;
- $sjId = $shop->sjId ?? 0;
- $customId = $shop->defaultCustomId ?? 0;
- if (empty($customId)) {
- noticeUtil::push("美团确认订单报错,没有找到客户哦,美团订单id:{$mtOrderId} 美团编号:{$thirdSn}", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $custom = CustomClass::getById($customId);
- if (empty($custom)) {
- noticeUtil::push("美团确认订单报错,没有找到客户,美团订单id:{$mtOrderId} 美团编号:{$thirdSn}", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- foreach ($post as $k => $val) {
- $post[$k] = urldecode($val);
- }
- MtOrderClass::add($post);
- $detail = $post['detail'] ?? '';
- if (empty($detail)) {
- noticeUtil::push("美团确认订单报错,没有找到商品,美团订单id:{$mtOrderId} 美团编号:{$thirdSn}", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $mtGoodsData = json_decode($detail, true);
- if (empty($mtGoodsData)) {
- noticeUtil::push("美团确认订单报错,没有找到商品哦,美团订单id:{$mtOrderId} 美团编号:{$thirdSn}", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- Yii::info('商品信息:' . json_encode($mtGoodsData));
- $productList = [];
- $mtCategory = CategoryClass::getByCondition(['mainId' => $mainId, 'style' => 1], true);
- if (empty($mtCategory)) {
- $mtCategory = CategoryClass::add(['style' => 1, 'categoryName' => '美团', 'mainId' => $mainId, 'sjId' => $sjId], true);
- }
- $catId = $mtCategory->id ?? 0;
- if (empty($catId)) {
- noticeUtil::push("美团确认订单报错,美团默认分类没有找到,美团订单id:{$mtOrderId} 美团编号:{$thirdSn}", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $caution = isset($post['caution']) && !empty($post['caution']) ? $post['caution'] : '';
- $remark = $caution;
- $bookMobile = $post['order_phone_number'] ?? '';
- $receiveMobile = $post['recipient_phone'] ?? '';
- $receiveUserName = $post['recipient_name'] ?? '';
- $fullAddress = $post['recipient_address'] ?? '';
- $cover = '';
- $goodsNum = 0;
- foreach ($mtGoodsData as $mtKey => $mtGoods) {
- $mtGoodsSpu = $mtGoods['app_spu_code'] ?? '';
- if (empty($mtGoodsSpu)) {
- if (isset($mtGoods['app_food_code']) && !empty($mtGoods['app_food_code'])) {
- $mtGoodsSpu = $mtGoods['app_food_code'];
- }
- }
- $goodsPrice = $mtGoods['price'] ?? 0;
- $num = $mtGoods['quantity'] ?? 0;
- $goodsNum = bcadd($num, $goodsNum);
- $currentGoods = GoodsClass::getByCondition(['spu' => $mtGoodsSpu], true);
- if (empty($currentGoods)) {
- noticeUtil::push("美团确认订单报错,数据库没有相应商品,美团订单id:{$mtOrderId} 美团编号:{$thirdSn}", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- $id = $currentGoods->id ?? 0;
- $unitType = 0;
- $property = dict::getDict('property', 'goods');
- $goods = [['productId' => $id, 'num' => $num, 'unitType' => $unitType, 'unitPrice' => $goodsPrice, 'property' => $property]];
- $productList = array_merge($goods, $productList);
- }
- $poi_receive_detail_yuan = $post['poi_receive_detail_yuan'] ?? '';
- if (empty($poi_receive_detail_yuan)) {
- noticeUtil::push("美团确认订单报错,订单金额有问题,美团订单id:{$mtOrderId} 美团编号:{$thirdSn}", '15280215347');
- util::stop();
- }
- $poi_receive_detail_yuan_data = json_decode($poi_receive_detail_yuan, true);
- if (is_array($poi_receive_detail_yuan_data) == false) {
- noticeUtil::push("美团确认订单报错,订单金额有问题哦,美团订单id:{$mtOrderId} 美团编号:{$thirdSn}", '15280215347');
- util::stop();
- }
- $onlinePayment = $poi_receive_detail_yuan_data['onlinePayment'] ?? 0;
- if ($onlinePayment == 0) {
- noticeUtil::push("美团确认订单报错,订单金额有问题!美团订单id:{$mtOrderId} 美团编号:{$thirdSn}", '15280215347');
- util::stop();
- }
- $modifyPrice = $onlinePayment;
- //技术服务费
- $foodShareFeeChargeByPoi = $poi_receive_detail_yuan_data['foodShareFeeChargeByPoi'] ?? 0;
- $reconciliationExtras = $poi_receive_detail_yuan_data['reconciliationExtras'] ?? '';
- //履约服务费
- $performanceServiceFee = 0;
- if (!empty($reconciliationExtras)) {
- $extArr = json_decode($reconciliationExtras, true);
- $performanceServiceFee = $extArr['performanceServiceFee'] ?? 0;
- }
- //运费
- $sendCost = $post['shipping_fee'] ?? 0;
- //打包费
- $labourCost = $post['package_bag_money_yuan'] ?? 0;
- //服务费和手续费
- $serviceFee = bcadd($foodShareFeeChargeByPoi, $performanceServiceFee, 2);
- $estimate_arrival_time = $post['estimate_arrival_time'] ?? 0;
- $reachPeriod = date("H:i", $estimate_arrival_time);
- $reachDate = date("Y-m-d", $estimate_arrival_time);
- $reachTime = $estimate_arrival_time;
- $orderData = [
- 'product' => $productList,
- 'fromType' => dict::getDict('fromType', 'mt'),
- 'labourCost' => $labourCost,
- 'sendCost' => $sendCost,
- 'shopId' => $shopId,
- 'mainId' => $mainId,
- 'sjId' => $sjId,
- 'modifyPrice' => $modifyPrice,
- 'serviceFee' => $serviceFee,
- 'thirdSn' => $thirdSn,
- 'cover' => $cover,
- 'reachTime' => $reachTime,
- 'reachDate' => $reachDate,
- 'reachPeriod' => $reachPeriod,
- 'remark' => $remark,
- 'goodsNum' => $goodsNum,
- 'bookMobile' => $bookMobile,
- 'receiveMobile' => $receiveMobile,
- 'receiveUserName' => $receiveUserName,
- 'fullAddress' => $fullAddress,
- 'thirdOrderId' => $mtOrderId,
- ];
- $hasPay = dict::getDict('hasPay', 'payed');
- //多处调用这个方法,注意同步修改,搜索关键词 createHdNewOrder 这个没有维护,可以不用考虑
- $order = OrderService::createHdOrder($orderData, $custom, $hasPay);
- $transaction->commit();
- //新制作单提示
- $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
- ShopExtClass::newWorkRemind($shopExt, $order);
- return Json::encode(['data' => 'ok']);
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- noticeUtil::push("确认订单报错了,美团订单id:{$mtOrderId} 美团编号:{$thirdSn},错误信息:{$msg}", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- }
- //取消订单
- public function actionCancelOrder()
- {
- return Json::encode(['data' => 'ok']);
- $post = Yii::$app->request->post();
- $mtOrderId = $post['order_id'] ?? 0;
- $shopId = $post['app_poi_code'] ?? '';
- if (empty($post)) {
- return Json::encode(['data' => 'ok']);
- }
- Yii::info('cancelOrderData: ' . json_encode($post));
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- //4秒内不允许第三方重复通知
- $cacheKey = 'mt_cancel_order_' . $mtOrderId;
- $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (!empty($has)) {
- Yii::info("美团取消订单通知,出现重复通知,orderId:{$mtOrderId}");
- return Json::encode(['data' => 'ok']);
- }
- Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 4, 'has']);
- $mt = dict::getDict('fromType', 'mt');
- $order = OrderClass::getByCondition(['fromType' => $mt, 'thirdOrderId' => $mtOrderId], true);
- if (empty($order)) {
- //没有接单时取消订单
- return Json::encode(['data' => 'ok']);
- }
- //订单取消,金额全部退还
- $shop = ShopClass::getById($shopId, true);
- if (empty($shop)) {
- return Json::encode(['data' => 'ok']);
- }
- $sjId = $shop->sjId ?? 0;
- $mainId = $shop->mainId ?? 0;
- $post = [];
- $post['price'] = $order->actPrice ?? 0;
- $post['refundType'] = HdRefundClass::REFUND_TYPE_MONEY_GOOD;
- $post['id'] = $order->id ?? 0;
- $post['shopId'] = $shopId;
- $post['sjId'] = $sjId;
- $post['shopAdminId'] = 0;
- $post['mainId'] = $mainId;
- $post['shopAdminName'] = '美团APP';
- $orderSn = $order->orderSn ?? '';
- $orderGoods = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- $productData = [];
- if (!empty($orderGoods)) {
- foreach ($orderGoods as $goodsItem) {
- $productData[] = ['productId' => $goodsItem->goodsId, 'num' => $goodsItem->num, 'unitPrice' => $goodsItem->unitPrice, 'property' => 0,];
- }
- }
- $orderItem = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($orderItem)) {
- foreach ($orderItem as $singe) {
- $productData[] = ['productId' => $singe->itemId, 'num' => $singe->num, 'unitPrice' => $singe->unitPrice, 'property' => 1,];
- }
- }
- $post['product'] = $productData;
- HdRefundService::addRefund($post, $order);
- $transaction->commit();
- //制作单取消通知
- $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
- ShopExtClass::orderCancelRemind($shopExt, $order);
- return Json::encode(['data' => 'ok']);
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- noticeUtil::push("取消报错了,美团订单id:{$mtOrderId} ,错误信息:{$msg}", '15280215347');
- return Json::encode(['data' => 'ok']);
- }
- }
- //推送已支付订单
- public function actionNewOrder()
- {
- return Json::encode(['data' => 'ok']);
- }
- //部分退款
- public function actionPartRefund()
- {
- return Json::encode(['data' => 'ok']);
- }
- //全部退款
- public function actionAllRefund()
- {
- return Json::encode(['data' => 'ok']);
- }
- }
|