BookController.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. if ($num <= 0) {
  19. echo "没有数量\n";
  20. return false;
  21. }
  22. if ($num > 15) {
  23. noticeUtil::push("assign seat all 已经超过15家了,请及时解决", '15280215347');
  24. }
  25. $list = Yii::$app->redis->executeCommand('SMEMBERS', [$cacheKey]);
  26. if (empty($list)) {
  27. echo "没有数量哦\n";
  28. return false;
  29. }
  30. Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
  31. Yii::$app->params['errorReport'] = 1;
  32. foreach ($list as $key => $bookSn) {
  33. $cgList = CgOrderClass::getAllByCondition(['bookSn' => $bookSn, 'status' => 3], null, '*', null, true);
  34. if (empty($cgList)) {
  35. noticeUtil::push("bookSn:{$bookSn} 没有采购单需要分配货位", '15280215347');
  36. continue;
  37. }
  38. foreach ($cgList as $cg) {
  39. $connection = Yii::$app->db;
  40. $transaction = $connection->beginTransaction();
  41. try {
  42. $respond = PurchaseOrderClass::assign($cg);
  43. $transaction->commit();
  44. $hasChange = $respond['hasChange'] ?? 0;
  45. if ($hasChange == 1) {
  46. //通知采购单页要刷新货位
  47. $cacheKey = 'ghs_cg_order_staff_refresh_seat_' . $bookSn;
  48. $mainId = $order->mainId ?? 0;
  49. $cgId = $cg->id ?? 0;
  50. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  51. if (!empty($staffList)) {
  52. foreach ($staffList as $staff) {
  53. $staffId = $staff->id ?? 0;
  54. $ele = $cgId . '-' . $staffId;
  55. Yii::$app->redis->executeCommand('SADD', [$cacheKey, $ele]);
  56. }
  57. }
  58. $cacheKey = 'ghs_cg_order_guest_refresh_seat_' . $bookSn;
  59. Yii::$app->redis->executeCommand('SADD', [$cacheKey, $cgId]);
  60. }
  61. } catch (\Exception $exception) {
  62. $transaction->rollBack();
  63. noticeUtil::push("部分门店待入库采购单,重新分配货位出错,原因:" . $exception->getMessage(), '15280215347');
  64. }
  65. }
  66. }
  67. }
  68. }