| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace console\controllers;
- use biz\shop\classes\ShopClass;
- use bizGhs\live\classes\LiveOrderClass;
- use bizGhs\live\classes\LiveOrderCustomClass;
- 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,'id,ptStyle,shopName',null,true);
- if(empty($shopList)){
- return false;
- }
- foreach($shopList as $shop){
- $mainId = $shop->mainId;
- $shopName = $shop->shopName??'';
- $sjName = $shop->merchantName??'';
- $name = $sjName.' '.$shopName;
- $cacheKey = 'live_order_' . $mainId;
- $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if(empty($has)){
- continue;
- }
- echo $cacheKey.' ';
- $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 = [];
- foreach ($list as $key => $live) {
- $addTime = $live['addTime'];
- $orderSn = $live['orderSn'];
- $itemId = $live['itemId'];
- $ptItemId = $live['ptItemId'];
- $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;
- }
- print_r($format);die;
- $hasPay = 2;
- $customId = 0;
- $custom = CustomClass::getCustom($customId);
- $post = [];
- $post['shopId'] =0;
- OrderService::createFinishOrder($post, $custom, $hasPay);
- //转换完了之后要清货位号!!!!!!!!!
- $transaction->commit();
- Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- noticeUtil::push($name." mainId:{$mainId} live order 报错了:".$msg, '15280215347');
- }
- }
- }
- }
|