LiveOrderController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. $connection = Yii::$app->db;
  33. $transaction = $connection->beginTransaction();
  34. try {
  35. $list = LiveOrderClass::getAllByCondition(['mainId' => $mainId,'switchOrder'=>0], null, '*');
  36. if(empty($list)){
  37. continue;
  38. }
  39. $customInfo = CustomClass::getAllByCondition(['ownMainId'=>$mainId],null,'*','id');
  40. $total = [];
  41. $format = [];
  42. foreach ($list as $key => $live) {
  43. $addTime = $live['addTime'];
  44. $orderSn = $live['orderSn'];
  45. $itemId = $live['itemId'];
  46. $ptItemId = $live['ptItemId'];
  47. $date = date("Y-m-d", strtotime($addTime));
  48. $customList = LiveOrderCustomClass::getAllByCondition(['orderSn'=>$orderSn],null,'*');
  49. if(empty($customList)){
  50. continue;
  51. }
  52. $total[$date] = 1;
  53. foreach($customList as $k => $v){
  54. $customId = $v['customId']??0;
  55. $num = $v['num']??0;
  56. $unitPrice = $v['unitPrice']??0;
  57. $currentCustom = $customInfo[$customId]??[];
  58. if(empty($currentCustom)){
  59. throw new \Exception("出现不存在的客户 customId:{$customId}");
  60. }
  61. $format[$customId][] =[
  62. 'productId'=>$itemId,
  63. 'bigNum'=>$num,
  64. 'itemId'=>$ptItemId,
  65. 'smallNum'=>0,
  66. 'price'=>$unitPrice,
  67. ];
  68. }
  69. }
  70. if (count($total) > 1) {
  71. noticeUtil::push($name." mainId:{$mainId} live order 有记录不是同一天的", '15280215347');
  72. continue;
  73. }
  74. print_r($format);die;
  75. $hasPay = 2;
  76. $customId = 0;
  77. $custom = CustomClass::getCustom($customId);
  78. $post = [];
  79. $post['shopId'] =0;
  80. OrderService::createFinishOrder($post, $custom, $hasPay);
  81. //转换完了之后要清货位号!!!!!!!!!
  82. $transaction->commit();
  83. Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
  84. } catch (\Exception $e) {
  85. $transaction->rollBack();
  86. $msg = $e->getMessage();
  87. noticeUtil::push($name." mainId:{$mainId} live order 报错了:".$msg, '15280215347');
  88. }
  89. }
  90. }
  91. }