BookController.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 = $cg->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. if (isset($staff->remind) && $staff->remind == 1) {
  54. $staffId = $staff->id ?? 0;
  55. $ele = $cgId . '-' . $staffId;
  56. Yii::$app->redis->executeCommand('SADD', [$cacheKey, $ele]);
  57. }
  58. }
  59. }
  60. $cacheKey = 'ghs_cg_order_guest_refresh_seat_' . $bookSn;
  61. Yii::$app->redis->executeCommand('SADD', [$cacheKey, $cgId]);
  62. }
  63. } catch (\Exception $exception) {
  64. $transaction->rollBack();
  65. noticeUtil::push("部分门店待入库采购单,重新分配货位出错,原因:" . $exception->getMessage(), '15280215347');
  66. }
  67. }
  68. }
  69. }
  70. }