BookController.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace console\controllers;
  3. use bizGhs\cg\classes\CgOrderClass;
  4. use bizGhs\order\classes\PurchaseOrderClass;
  5. use bizGhs\shop\classes\ShopAdminClass;
  6. use common\components\noticeUtil;
  7. use yii\console\Controller;
  8. use Yii;
  9. class BookController extends Controller
  10. {
  11. //全部待入库采购单重新分配货位 ssh 20240711
  12. public function actionAssignSeat()
  13. {
  14. ini_set('memory_limit', '2045M');
  15. set_time_limit(0);
  16. $cacheKey = 'assign_seat_main_book_sn_list';
  17. $num = Yii::$app->redis->executeCommand('SCARD', [$cacheKey]);
  18. noticeUtil::push("每三分钟执行一次吗", '15280215347');
  19. if ($num <= 0) {
  20. echo "没有数量\n";
  21. return false;
  22. }
  23. if ($num > 15) {
  24. noticeUtil::push("assign seat all 已经超过15家了,请及时解决", '15280215347');
  25. }
  26. $list = Yii::$app->redis->executeCommand('SMEMBERS', [$cacheKey]);
  27. if (empty($list)) {
  28. echo "没有数量哦\n";
  29. return false;
  30. }
  31. Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
  32. Yii::$app->params['errorReport'] = 1;
  33. foreach ($list as $key => $bookSn) {
  34. $cgList = CgOrderClass::getAllByCondition(['bookSn' => $bookSn, 'status' => 3], null, '*', null, true);
  35. if (empty($cgList)) {
  36. foreach ($cgList as $cg) {
  37. $connection = Yii::$app->db;
  38. $transaction = $connection->beginTransaction();
  39. try {
  40. $respond = PurchaseOrderClass::assign($cg);
  41. $transaction->commit();
  42. $hasChange = $respond['hasChange'] ?? 0;
  43. if ($hasChange == 1) {
  44. //通知采购单页要刷新货位
  45. $cacheKey = 'ghs_cg_order_staff_refresh_seat_' . $bookSn;
  46. $mainId = $order->mainId ?? 0;
  47. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  48. if (!empty($staffList)) {
  49. foreach ($staffList as $staff) {
  50. $staffId = $staff->id ?? 0;
  51. $params = $cgId . '-' . $staffId;
  52. Yii::$app->redis->executeCommand('SADD', [$cacheKey, $params]);
  53. }
  54. }
  55. $cacheKey = 'ghs_cg_order_guest_refresh_seat_' . $bookSn;
  56. Yii::$app->redis->executeCommand('SADD', [$cacheKey, $cgId]);
  57. }
  58. } catch (\Exception $exception) {
  59. $transaction->rollBack();
  60. noticeUtil::push("部分门店待入库采购单,重新分配货位出错,原因:" . $exception->getMessage(), '15280215347');
  61. }
  62. }
  63. }
  64. }
  65. }
  66. }