OrderSendClass.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace bizGhs\order\classes;
  3. use bizGhs\base\classes\BaseClass;
  4. use common\components\util;
  5. class OrderSendClass extends BaseClass
  6. {
  7. public static $baseFile = '\bizGhs\order\models\OrderSend';
  8. //流程键名与ID关系
  9. const ACTION_RELATION = ['placeOrder' => 10, 'deliver' => 30, 'reach' => 40];
  10. const ACTION_LIST = [
  11. 10 => ['name' => '下单', 'sign' => 'placeOrder'],
  12. 30 => ['name' => '发货', 'sign' => 'deliver'],
  13. 40 => ['name' => '送达', 'sign' => 'reach']
  14. ];
  15. public static function thirdSend($order)
  16. {
  17. $orderSn = $order->orderSn;
  18. $relation = self::ACTION_RELATION;
  19. $currentId = $relation['deliver'] ?? 0;
  20. if (empty($currentId)) {
  21. util::fail('没有找到流程');
  22. }
  23. $send = self::getByCondition(['orderSn' => $orderSn, 'actionId' => $currentId], true);
  24. if (empty($send)) {
  25. return false;
  26. util::fail('配送信息错误');
  27. }
  28. //0没有选择 1本店送 2发快递
  29. $send->option = 2;
  30. $send->status = 0;
  31. $send->finishTime = date("Y-m-d H:i:s");
  32. $send->save();
  33. }
  34. //本店送 ssh 2021.3.4
  35. public static function selfSend($order)
  36. {
  37. $orderSn = $order->orderSn;
  38. $relation = self::ACTION_RELATION;
  39. $currentId = $relation['deliver'] ?? 0;
  40. if (empty($currentId)) {
  41. util::fail('没有找到流程');
  42. }
  43. $send = self::getByCondition(['orderSn' => $orderSn, 'actionId' => $currentId], true);
  44. if (empty($send)) {
  45. return false;
  46. util::fail('配送信息错误');
  47. }
  48. //0没有选择 1本店送 2发快递
  49. $send->option = 1;
  50. $send->status = 0;
  51. $send->finishTime = date("Y-m-d H:i:s");
  52. $send->save();
  53. }
  54. //下单操作完成 ssh 2019.12.13
  55. public static function placeOrder($data)
  56. {
  57. //下单完成
  58. $orderSn = $data['orderSn'];
  59. $payTime = $data['payTime'];
  60. $relation = self::ACTION_RELATION;
  61. $actionList = self::ACTION_LIST;
  62. $currentId = $relation['placeOrder'] ?? 0;
  63. if (empty($currentId)) {
  64. util::fail('没有找到流程');
  65. }
  66. $currentName = $actionList[$currentId]['name'] ?? '';
  67. $data = ['actionId' => $currentId, 'actionName' => $currentName, 'orderSn' => $orderSn, 'finishTime' => $payTime, 'inTurn' => $currentId, 'status' => 1];
  68. self::add($data);
  69. OrderClass::updateByCondition(['orderSn' => $orderSn], ['currentFlow' => 1]);
  70. //配送未开始
  71. $nextId = $relation['deliver'] ?? 0;
  72. if (empty($nextId)) {
  73. util::fail('下单后没有找到下一步的流程ID');
  74. }
  75. $nextName = $actionList[$nextId]['name'] ?? '';
  76. $data = ['actionId' => $nextId, 'actionName' => $nextName, 'orderSn' => $orderSn, 'inTurn' => $nextId, 'status' => 0];
  77. self::add($data);
  78. }
  79. //当前待执行的动作 ssh 2019.12.16
  80. public static function toDoActionId($orderSn)
  81. {
  82. $action = self::getByCondition(['orderSn' => $orderSn], false, 'inTurn DESC');
  83. $actionId = 0;
  84. if (empty($action['finishTime'])) {
  85. $actionId = $action['actionId'];
  86. }
  87. return $actionId;
  88. }
  89. //送达 ssh 2020.6.1
  90. public static function reach($order)
  91. {
  92. $orderSn = $order['orderSn'];
  93. $time = date("Y-m-d H:i:s");
  94. $relation = self::ACTION_RELATION;
  95. $actionList = self::ACTION_LIST;
  96. $currentId = $relation['reach'] ?? 0;
  97. if (empty($currentId)) {
  98. util::fail('没有找到流程');
  99. }
  100. $currentName = $actionList[$currentId]['name'] ?? '';
  101. $has = OrderSendClass::getByCondition(['orderSn' => $orderSn, 'actionId' => $currentId]);
  102. if ($has) {
  103. util::fail('已经确认送达');
  104. }
  105. $preActionId = $relation['deliver'] ?? 0;
  106. $preInfo = OrderSendClass::getByCondition(['orderSn' => $orderSn, 'actionId' => $preActionId], true);
  107. if (empty($preInfo)) {
  108. return false;
  109. util::fail('配送信息错误,没有找到前面个流程');
  110. }
  111. $preInfo->status = 1;
  112. $preInfo->save();
  113. $sendData = ['actionId' => $currentId, 'actionName' => $currentName, 'orderSn' => $orderSn, 'finishTime' => $time, 'inTurn' => $currentId, 'status' => 1];
  114. OrderSendClass::add($sendData);
  115. }
  116. //免发货和自取流程处理 ssh 2021.1.24
  117. public static function withoutSend($info)
  118. {
  119. $orderSn = $info->orderSn ?? '';
  120. if (empty($orderSn)) {
  121. util::faill('没有找到订单编号');
  122. }
  123. self::deleteByCondition(['orderSn' => $orderSn]);
  124. }
  125. }