|
|
@@ -5,6 +5,7 @@ namespace hd\controllers;
|
|
|
use biz\shop\classes\ShopExtClass;
|
|
|
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;
|
|
|
@@ -26,11 +27,294 @@ class MtController extends PublicController
|
|
|
|
|
|
public $guestAccess = [];
|
|
|
|
|
|
+ public function actionGoodsAdd()
|
|
|
+ {
|
|
|
+ $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信息", '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']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $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']);
|
|
|
+ }
|
|
|
+
|
|
|
+ noticeUtil::push("美团添加商品,通知我们,商品图片:" . $imgString, '15280215347');
|
|
|
+
|
|
|
+ $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']);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除商品 ssh 20220914
|
|
|
+ public function actionGoodsDel()
|
|
|
+ {
|
|
|
+ $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信息", '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()
|
|
|
+ {
|
|
|
+ $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信息", '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, '15280215347');
|
|
|
+
|
|
|
+ $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()
|
|
|
{
|
|
|
//error_reporting(E_ALL);
|
|
|
-
|
|
|
$post = Yii::$app->request->post();
|
|
|
$mtOrderId = $post['order_id'] ?? 0;
|
|
|
$thirdSn = $post['day_seq'] ?? 0;
|
|
|
@@ -111,7 +395,7 @@ class MtController extends PublicController
|
|
|
$receiveUserName = $post['recipient_name'] ?? '';
|
|
|
$fullAddress = $post['recipient_address'] ?? '';
|
|
|
|
|
|
- $orderCover = '';
|
|
|
+ $cover = '';
|
|
|
|
|
|
$goodsNum = 0;
|
|
|
foreach ($mtGoodsData as $mtKey => $mtGoods) {
|
|
|
@@ -182,7 +466,7 @@ class MtController extends PublicController
|
|
|
'modifyPrice' => $modifyPrice,
|
|
|
'serviceFee' => $serviceFee,
|
|
|
'thirdSn' => $thirdSn,
|
|
|
- 'cover' => $orderCover,
|
|
|
+ 'cover' => $cover,
|
|
|
'reachTime' => $reachTime,
|
|
|
'reachDate' => $reachDate,
|
|
|
'reachPeriod' => $reachPeriod,
|
|
|
@@ -243,28 +527,16 @@ class MtController extends PublicController
|
|
|
//只要制作单没有完成,则走取消订单流程。如果有制作单完成,则订单状态和制作单暂时先不管,后面要兼容。
|
|
|
$orderId = $order->id ?? 0;
|
|
|
$workList = WorkClass::getAllByCondition(['orderId' => $orderId], null, '*', null, true);
|
|
|
- $hasCompleteWork = false;
|
|
|
if (!empty($workList)) {
|
|
|
foreach ($workList as $work) {
|
|
|
- if ($work->status == 1) {
|
|
|
- $hasCompleteWork = true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //取消订单和制作单
|
|
|
- if ($hasCompleteWork == false) {
|
|
|
- $order->status = 5;
|
|
|
- $order->save();
|
|
|
- if (!empty($workList)) {
|
|
|
- foreach ($workList as $work) {
|
|
|
+ if ($work->status == 0) {
|
|
|
$work->status = 2;
|
|
|
$work->save();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ //订单取消,金额全部退还
|
|
|
|
|
|
- //如果制作单完成了还会出现取消订单情况,这个等于全部退款,这个后面再考虑兼容!!!!!
|
|
|
|
|
|
//制作单取消通知
|
|
|
$shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
|