BookItemGhsClass.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace bizGhs\book\classes;
  3. use bizGhs\base\classes\BaseClass;
  4. use bizGhs\cg\classes\CgOrderItemClass;
  5. use bizGhs\cg\classes\CgOrderItemSendClass;
  6. use bizGhs\shop\classes\ShopAdminClass;
  7. use common\components\util;
  8. use Yii;
  9. class BookItemGhsClass extends BaseClass
  10. {
  11. public static $baseFile = '\bizGhs\book\models\BookItemGhs';
  12. public static function delRoadNum($bookItemCustomRes, $totalNum, $bookSn, $order)
  13. {
  14. $bookItemCustomResId = $bookItemCustomRes->id ?? 0;
  15. $ghsList = self::getAllByCondition(['parentId' => $bookItemCustomResId], null, '*', null, true);
  16. if (empty($ghsList)) {
  17. //有预订单但还没有采购单时会这样
  18. return true;
  19. }
  20. foreach ($ghsList as $ghsRes) {
  21. $status = $ghsRes->status ?? 0;
  22. if ($status != 0) {
  23. continue;
  24. }
  25. if ($totalNum <= 0) {
  26. break;
  27. }
  28. $num = $ghsRes->num ?? 0;
  29. $cgSendId = $ghsRes->cgSendId ?? 0;
  30. $send = CgOrderItemSendClass::getById($cgSendId, true);
  31. if (empty($send)) {
  32. util::fail('预订减少删路上数时,没找到供货2');
  33. }
  34. $cgOrderId = $send->parentOrderId ?? 0;
  35. $cgOrderItemId = $send->parentId ?? 0;
  36. $cgOrderItemRes = CgOrderItemClass::getById($cgOrderItemId, true);
  37. if (empty($cgOrderItemRes)) {
  38. util::fail('预订减少删路上数时,没找到供货3');
  39. }
  40. if ($num >= $totalNum) {
  41. $delNum = $totalNum;
  42. } else {
  43. $delNum = $num;
  44. }
  45. $totalNum = bcsub($totalNum, $delNum);
  46. $ghsRemainNum = bcsub($ghsRes->num, $delNum);
  47. $ghsRes->num = $ghsRemainNum;
  48. $ghsRes->save();
  49. $sendRemainNum = bcsub($send->num, $delNum);
  50. $send->num = $sendRemainNum;
  51. $send->save();
  52. $confirmSendNum = $cgOrderItemRes->confirmSendNum ?? 0;
  53. $lastConfirm = bcsub($confirmSendNum, $delNum);
  54. if ($lastConfirm < 0) {
  55. util::fail('预订减少删路上数时,没找到供货4');
  56. }
  57. $cgOrderItemRes->confirmSendNum = $lastConfirm;
  58. $cgOrderItemRes->save();
  59. //通知采购单页要刷新货位
  60. $cacheKey = 'ghs_cg_order_staff_refresh_seat_' . $bookSn;
  61. $mainId = $order->mainId ?? 0;
  62. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  63. if (!empty($staffList)) {
  64. foreach ($staffList as $staff) {
  65. $staffId = $staff->id ?? 0;
  66. $ele = $cgOrderId . '-' . $staffId;
  67. Yii::$app->redis->executeCommand('SADD', [$cacheKey, $ele]);
  68. }
  69. }
  70. $cacheKey = 'ghs_cg_order_guest_refresh_seat_' . $bookSn;
  71. Yii::$app->redis->executeCommand('SADD', [$cacheKey, $cgOrderId]);
  72. }
  73. }
  74. }