LiveOrderController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace console\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use bizGhs\live\classes\LiveOrderClass;
  5. use bizGhs\live\classes\LiveOrderCustomClass;
  6. use common\components\noticeUtil;
  7. use bizGhs\custom\classes\CustomClass;
  8. use bizGhs\order\services\OrderService;
  9. use yii\console\Controller;
  10. use Yii;
  11. class LiveOrderController extends Controller
  12. {
  13. //每二分钟执行一次 ssh 20241006
  14. public function actionSeat()
  15. {
  16. ini_set('memory_limit', '2045M');
  17. set_time_limit(0);
  18. $shopList = ShopClass::getAllByCondition(['ptStyle'=>2],null,'id,ptStyle,shopName',null,true);
  19. if(empty($shopList)){
  20. return false;
  21. }
  22. foreach($shopList as $shop){
  23. $mainId = $shop->mainId;
  24. $shopName = $shop->shopName??'';
  25. $sjName = $shop->merchantName??'';
  26. $name = $sjName.' '.$shopName;
  27. $cacheKey = 'live_order_' . $mainId;
  28. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  29. if(empty($has)){
  30. continue;
  31. }
  32. echo $cacheKey.' ';
  33. $connection = Yii::$app->db;
  34. $transaction = $connection->beginTransaction();
  35. try {
  36. $list = LiveOrderClass::getAllByCondition(['mainId' => $mainId,'switchOrder'=>0], null, '*');
  37. if(empty($list)){
  38. continue;
  39. }
  40. $customInfo = CustomClass::getAllByCondition(['ownMainId'=>$mainId],null,'*','id');
  41. $total = [];
  42. $format = [];
  43. foreach ($list as $key => $live) {
  44. $addTime = $live['addTime'];
  45. $orderSn = $live['orderSn'];
  46. $itemId = $live['itemId'];
  47. $ptItemId = $live['ptItemId'];
  48. $date = date("Y-m-d", strtotime($addTime));
  49. $customList = LiveOrderCustomClass::getAllByCondition(['orderSn'=>$orderSn],null,'*');
  50. if(empty($customList)){
  51. continue;
  52. }
  53. $total[$date] = 1;
  54. foreach($customList as $k => $v){
  55. $customId = $v['customId']??0;
  56. $num = $v['num']??0;
  57. $unitPrice = $v['unitPrice']??0;
  58. $currentCustom = $customInfo[$customId]??[];
  59. if(empty($currentCustom)){
  60. throw new \Exception("出现不存在的客户 customId:{$customId}");
  61. }
  62. $format[$customId][] =[
  63. 'productId'=>$itemId,
  64. 'bigNum'=>$num,
  65. 'itemId'=>$ptItemId,
  66. 'smallNum'=>0,
  67. 'price'=>$unitPrice,
  68. ];
  69. }
  70. }
  71. if (count($total) > 1) {
  72. noticeUtil::push($name." mainId:{$mainId} live order 有记录不是同一天的", '15280215347');
  73. continue;
  74. }
  75. print_r($format);die;
  76. $hasPay = 2;
  77. $customId = 0;
  78. $custom = CustomClass::getCustom($customId);
  79. $post = [];
  80. $post['shopId'] =0;
  81. OrderService::createFinishOrder($post, $custom, $hasPay);
  82. //转换完了之后要清货位号!!!!!!!!!
  83. $transaction->commit();
  84. Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
  85. } catch (\Exception $e) {
  86. $transaction->rollBack();
  87. $msg = $e->getMessage();
  88. noticeUtil::push($name." mainId:{$mainId} live order 报错了:".$msg, '15280215347');
  89. }
  90. }
  91. }
  92. }