| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- <?php
- namespace console\controllers;
- use biz\shop\classes\ShopClass;
- use bizGhs\live\classes\LiveOrderClass;
- use bizGhs\live\classes\LiveOrderCustomClass;
- use bizGhs\live\classes\LiveSeatClass;
- use common\components\dict;
- use common\components\noticeUtil;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\order\services\OrderService;
- use yii\console\Controller;
- use Yii;
- class LiveOrderController extends Controller
- {
- //每二分钟执行一次 ssh 20241006
- public function actionSeat()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $shopList = ShopClass::getAllByCondition(['ptStyle' => 2], null, '*', null, true);
- if (empty($shopList)) {
- return false;
- }
- Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
- Yii::$app->params['errorReport'] = 1;
- foreach ($shopList as $shop) {
- $mainId = $shop->mainId;
- $shopName = $shop->shopName ?? '';
- $sjName = $shop->merchantName ?? '';
- $shopId = $shop->id ?? 0;
- $sjId = $shop->sjId ?? 0;
- $name = $sjName . ' ' . $shopName;
- $cacheKey = 'live_order_' . $mainId;
- $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (empty($has)) {
- continue;
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $list = LiveOrderClass::getAllByCondition(['mainId' => $mainId, 'switchOrder' => 0], null, '*');
- if (empty($list)) {
- continue;
- }
- $customInfo = CustomClass::getAllByCondition(['ownMainId' => $mainId], null, '*', 'id');
- $total = [];
- $format = [];
- $staffId = 0;
- $staffName = '';
- $historyDate = date("Y-m-d");
- foreach ($list as $key => $live) {
- $liveId = $live['id'] ?? 0;
- LiveOrderClass::updateById($liveId, ['switchOrder' => 1]);
- $addTime = $live['addTime'];
- $historyDate = date("Y-m-d", strtotime($addTime));
- $orderSn = $live['orderSn'];
- $itemId = $live['itemId'];
- $ptItemId = $live['ptItemId'];
- $staffId = $live['staffId'] ?? 0;
- $staffName = $live['staffName'] ?? '';
- $date = date("Y-m-d", strtotime($addTime));
- $customList = LiveOrderCustomClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
- if (empty($customList)) {
- continue;
- }
- $total[$date] = 1;
- foreach ($customList as $k => $v) {
- $customId = $v['customId'] ?? 0;
- $num = $v['num'] ?? 0;
- $unitPrice = $v['unitPrice'] ?? 0;
- $currentCustom = $customInfo[$customId] ?? [];
- if (empty($currentCustom)) {
- throw new \Exception("出现不存在的客户 customId:{$customId}");
- }
- $format[$customId][] = [
- 'productId' => $itemId,
- 'bigNum' => $num,
- 'itemId' => $ptItemId,
- 'smallNum' => 0,
- 'price' => $unitPrice,
- ];
- }
- }
- if (count($total) > 1) {
- noticeUtil::push($name . " mainId:{$mainId} live order 有记录不是同一天的", '15280215347');
- continue;
- }
- if (empty($format)) {
- noticeUtil::push($name . " mainId:{$mainId} live order 没有找到客户预订", '15280215347');
- continue;
- }
- foreach ($format as $customId => $mat) {
- $modifyPrice = 0;
- foreach ($mat as $ma) {
- $cNum = $ma['bigNum'] ?? 0;
- $cPrice = $ma['price'] ?? 0;
- $cTotal = bcmul($cNum, $cPrice, 2);
- $modifyPrice = bcadd($modifyPrice, $cTotal, 2);
- }
- $currentCustom = $customInfo[$customId] ?? [];
- if (empty($currentCustom)) {
- throw new \Exception("出现不存在的客户哦 customId:{$customId}");
- }
- $customName = $currentCustom['name'] ?? '';
- $customMobile = $currentCustom['mobile'] ?? '';
- $customPy = $currentCustom['py'] ?? '';
- $ghsId = $currentCustom['ghsId'] ?? 0;
- $hasPay = 2;
- $custom = CustomClass::getCustom($customId);
- $post = [];
- $post['modifyPrice'] = $modifyPrice;
- $post['shopId'] = $shopId;
- $post['sendType'] = 0;
- $post['transType'] = 0;
- $post['sendSide'] = 0;
- $post['sendCost'] = 0;
- $post['packCost'] = 0;
- $post['customId'] = $customId;
- $post['customName'] = $customName;
- $post['payWay'] = 0;
- $post['needPrint'] = 2;
- $post['hasPay'] = 2;
- $post['product'] = $mat;
- $post['deadline'] = date("Y-m-d H:i:s", time() + 86400);
- $post['debt'] = 1;
- $post['mainId'] = $mainId;
- $post['fromType'] = 1;
- $post['expressId'] = 0;
- $post['sjId'] = $sjId;
- $post['shopAdminId'] = $staffId;
- $post['shopAdminName'] = $staffName;
- $post['getStaffId'] = $staffId;
- $post['getStaffName'] = $staffName;
- $post['customMobile'] = $customMobile;
- $post['customNamePy'] = $customPy;
- $post['customAvatar'] = '';
- $post['newVersion'] = 1;
- $post['book'] = 0;
- $post['wlName'] = '';
- $post['dealPrice'] = 1;
- $post['ghsId'] = $ghsId;
- $post['historyDate'] = $historyDate;
- //多处有用到此方法,需要同步修改,搜索关键词create_new_order
- $order = OrderService::createNewOrder($post, $custom, $hasPay);
- //清掉一天多单的汇总
- $sameDate = date("Y_m_d");
- $sameAddress = $order->showAddress ?? '';
- $addressMd5 = md5($sameAddress);
- $sameKey = $customId . '_' . $addressMd5 . '_' . $sameDate;
- Yii::$app->redis->executeCommand('DEL', [$sameKey]);
- }
- //清空货位
- CustomClass::updateByCondition(['ownMainId' => $mainId], ['seatSn' => 0, 'printSeatSn' => 0]);
- LiveSeatClass::updateByCondition(['mainId' => $mainId], ['customId' => 0, 'customName' => '']);
- $transaction->commit();
- Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
- noticeUtil::push($name . " mainId:{$mainId} live order 转换订单成功", '15280215347');
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- noticeUtil::push($name . " mainId:{$mainId} live order 报错了:" . $msg, '15280215347');
- }
- }
- }
- }
|