BookController.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace console\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use bizGhs\cg\classes\CgOrderClass;
  5. use bizGhs\order\classes\PurchaseOrderClass;
  6. use bizGhs\shop\classes\ShopAdminClass;
  7. use common\components\noticeUtil;
  8. use yii\console\Controller;
  9. use Yii;
  10. class BookController extends Controller
  11. {
  12. //全部待入库采购单重新分配货位 ssh 20240711
  13. public function actionAssignSeat()
  14. {
  15. ini_set('memory_limit', '2045M');
  16. set_time_limit(0);
  17. $cacheKey = 'assign_seat_main_book_sn_list';
  18. $num = Yii::$app->redis->executeCommand('SCARD', [$cacheKey]);
  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. //noticeUtil::push("bookSn:{$bookSn} 没有采购单需要分配货位", '15280215347');
  37. continue;
  38. }
  39. foreach ($cgList as $cg) {
  40. $connection = Yii::$app->db;
  41. $transaction = $connection->beginTransaction();
  42. try {
  43. $shopId = $cg->shopId??0;
  44. $shop = ShopClass::getById($shopId,true);
  45. if(empty($shop)){
  46. continue;
  47. }
  48. $staffId = $cg->shopAdminId??0;
  49. $staffName = $cg->shopAdminName??'';
  50. $params = ['staffId'=>$staffId,'staffName'=>$staffName];
  51. $respond = PurchaseOrderClass::assign($cg,$shop,$params);
  52. $transaction->commit();
  53. $hasChange = $respond['hasChange'] ?? 0;
  54. if ($hasChange == 1) {
  55. //通知采购单页要刷新货位
  56. $cacheKey = 'ghs_cg_order_staff_refresh_seat_' . $bookSn;
  57. $mainId = $cg->mainId ?? 0;
  58. $cgId = $cg->id ?? 0;
  59. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  60. if (!empty($staffList)) {
  61. foreach ($staffList as $staff) {
  62. if (isset($staff->remind) && $staff->remind == 1) {
  63. $staffId = $staff->id ?? 0;
  64. $ele = $cgId . '-' . $staffId;
  65. Yii::$app->redis->executeCommand('SADD', [$cacheKey, $ele]);
  66. }
  67. }
  68. }
  69. $cacheKey = 'ghs_cg_order_guest_refresh_seat_' . $bookSn;
  70. Yii::$app->redis->executeCommand('SADD', [$cacheKey, $cgId]);
  71. }
  72. } catch (\Exception $exception) {
  73. $transaction->rollBack();
  74. noticeUtil::push("部分门店待入库采购单,重新分配货位出错,原因:" . $exception->getMessage(), '15280215347');
  75. }
  76. }
  77. }
  78. }
  79. }