OrderNo.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\utils;
  8. use app\models\AlipayActivityDelivery;
  9. use app\models\AlipayVoucherCode;
  10. use app\models\Cash;
  11. use app\models\LevelOrder;
  12. use app\models\Mch;
  13. use app\models\MchCash;
  14. use app\models\Order;
  15. use app\models\OrderUnion;
  16. use app\models\ReOrder;
  17. use app\models\SaasProfitCash;
  18. use app\models\StoreReOrder;
  19. use app\models\BusinessMemberOrder;
  20. use app\models\LocalDeliveryCash;
  21. use app\plugins\adopt\models\AdoptCostOrder;
  22. use app\plugins\food\models\FoodOrder;
  23. use app\plugins\integral\models\SaasIntegralOrder;
  24. use app\models\PurchaseOrder;
  25. class OrderNo
  26. {
  27. /**
  28. * 定义订单类型,统一订单号,以便回调后续统一处理
  29. */
  30. const ORDER_MALL = 'ML'; // 商城订单
  31. const ORDER_MS = 'MS'; // 秒杀订单
  32. const ORDER_PT = 'PT'; // 拼团订单
  33. const ORDER_BOOK = 'YY'; // 预约订单
  34. const ORDER_BARGAIN = 'BG'; // 砍价订单
  35. const ORDER_INTEGRAL = 'IG'; // 积分订单
  36. const ORDER_LOTTERY = 'LT'; // 抽奖订单
  37. const ORDER_SUPPLIER = 'SP'; // 供货商订单
  38. const ORDER_RECHARGE = 'RG'; // 充值订单
  39. const INTEGRAL_RECHARGE = 'IR'; // 积分充值订单
  40. const ORDER_UNION = 'UN'; // 联合订单
  41. const ORDER_CASH = 'CS'; // 提现订单
  42. const ORDER_LOCAL_CASH = 'LCS'; // 同城配送提现订单
  43. const ORDER_MCH_CASH = 'MC'; // 商户提现订单
  44. const ORDER_LEVEL = 'LV'; // 会员订单
  45. const ORDER_INTEGRAL_COUPON = 'IC'; // 积分卡券
  46. const ORDER_SCRATCH = 'ST'; // 红包
  47. const ORDER_STEP = 'TP'; // 步数宝
  48. const ORDER_POND = 'PD'; // 大转盘
  49. const ORDER_BARGAIN_REFUND = 'BF'; // 砍价退款订单
  50. const ORDER_SCAN_CODE_PAY = 'SC'; // 当面付订单
  51. const ORDER_SAAS_INTEGRAL = 'SI'; // saas积分订单
  52. const ORDER_SAAS_PROFIT_CASH = 'PC'; // 联盟佣金订单
  53. const ORDER_ALIPAY_FOOD = 'FO'; // 点餐订单
  54. const ORDER_ALIPAY_SCAN = 'AC'; // 支付宝当面付订单
  55. const ORDER_ALLIANCE = 'AL'; // 商盟订单
  56. const ORDER_ALLIANCE_PURCHASE = 'AP'; // 商盟采购订单
  57. const ORDER_PURCHASE_RE = 'PR'; // 商盟采购员充值
  58. const ORDER_ALLIANCE_MEMBER = 'AM'; // 商盟会员卡
  59. const STORE_ORDER_RECHARGE = 'SG'; // 充值订单
  60. const ADOPT_COST_ORDER = 'AD'; // 认养费用订单
  61. const ALIPAY_ACTIVITY_DELIVERY = 'AAD'; // 推广活动外部订单
  62. const ALIPAY_VOUCHAR_CODE = 'VC';//支付宝券码外部单号
  63. const LEAGUE_PRICE = 'LP';//商城联盟券充值
  64. const ERP_PURCHASE = 'EP';//ERP采购单
  65. const ERP_PURCHASE_IN = 'EQ';//ERP入库单
  66. const ERP_PURCHASE_OUT = 'EO';//ERP出库单
  67. const REPORT_INFO = 'RE';//全域产品
  68. public static $validOrderType = [
  69. self::ORDER_MALL,
  70. self::ORDER_MS,
  71. self::ORDER_PT,
  72. self::ORDER_BOOK,
  73. self::ORDER_BARGAIN,
  74. self::ORDER_INTEGRAL,
  75. self::ORDER_LOTTERY,
  76. self::ORDER_SUPPLIER,
  77. self::ORDER_RECHARGE,
  78. self::ORDER_UNION,
  79. self::ORDER_CASH,
  80. self::ORDER_LOCAL_CASH,
  81. self::ORDER_LEVEL,
  82. self::ORDER_INTEGRAL_COUPON,
  83. self::ORDER_SCRATCH,
  84. self::ORDER_STEP,
  85. self::ORDER_POND,
  86. self::ORDER_BARGAIN_REFUND,
  87. self::ORDER_MCH_CASH,
  88. self::ORDER_SCAN_CODE_PAY,
  89. self::ORDER_SAAS_INTEGRAL,
  90. self::ORDER_SAAS_PROFIT_CASH,
  91. self::ORDER_ALIPAY_FOOD,
  92. self::STORE_ORDER_RECHARGE,
  93. self::ORDER_ALLIANCE,
  94. self::ORDER_ALLIANCE_PURCHASE,
  95. self::LEAGUE_PRICE,
  96. self::ORDER_PURCHASE_RE,
  97. self::ORDER_ALLIANCE_MEMBER,
  98. self::ADOPT_COST_ORDER,
  99. self::ALIPAY_ACTIVITY_DELIVERY,
  100. self::ALIPAY_VOUCHAR_CODE,
  101. self::REPORT_INFO,
  102. self::ERP_PURCHASE,
  103. self::ERP_PURCHASE_IN,
  104. ];
  105. public static function checkOrderNo($order_no, $type)
  106. {
  107. if(!empty($type) && (strpos($order_no, $type) !== false)){
  108. return true;
  109. }
  110. return false;
  111. }
  112. /**
  113. * 根据订单类型生成订单号
  114. * @param $type
  115. * @return null | string
  116. */
  117. public static function getOrderNo($type)
  118. {
  119. $order_no = null;
  120. while (true) {
  121. $order_no = $type.date('YmdHis') . mt_rand(100000, 999999);
  122. switch ($type) {
  123. case self::ORDER_MALL:
  124. $exist_order_no = Order::find()->where(['order_no' => $order_no])->exists();
  125. break;
  126. // case self::ORDER_MS:
  127. // $exist_order_no = MsOrder::find()->where(['order_no' => $order_no])->exists();
  128. // break;
  129. // case self::ORDER_PT:
  130. // $exist_order_no = PtOrder::find()->where(['order_no' => $order_no])->exists();
  131. // break;
  132. // case self::ORDER_BOOK:
  133. // $exist_order_no = YyOrder::find()->where(['order_no' => $order_no])->exists();
  134. // break;
  135. // case self::ORDER_BARGAIN:
  136. // $exist_order_no = BargainOrder::find()->where(['order_no' => $order_no])->exists();
  137. // break;
  138. // case self::ORDER_INTEGRAL:
  139. // $exist_order_no = IntegralOrder::find()->where(['order_no' => $order_no])->exists();
  140. // break;
  141. // case self::ORDER_SUPPLIER:
  142. // $exist_order_no = SupplierOrderNew::find()->where(['order_no' => $order_no])->exists();
  143. // break;
  144. case self::ORDER_RECHARGE:
  145. $exist_order_no = ReOrder::find()->where(['order_no' => $order_no])->exists();
  146. break;
  147. case self::ORDER_UNION:
  148. $exist_order_no = OrderUnion::find()->where(['order_no' => $order_no])->exists();
  149. break;
  150. case self::ORDER_CASH:
  151. $exist_order_no = Cash::find()->where(['order_no' => $order_no])->exists();
  152. break;
  153. case self::ORDER_LOCAL_CASH:
  154. $exist_order_no = LocalDeliveryCash::find()->where(['order_no' => $order_no])->exists();
  155. break;
  156. case self::ORDER_MCH_CASH:
  157. $exist_order_no = MchCash::find()->where(['order_no' => $order_no])->exists();
  158. break;
  159. case self::ORDER_LEVEL:
  160. $exist_order_no = LevelOrder::find()->where(['order_no' => $order_no])->exists();
  161. break;
  162. case self::ORDER_SCAN_CODE_PAY:
  163. $exist_order_no = \app\plugins\scanCodePay\models\Order::find()->where(['order_no' => $order_no])->exists();
  164. break;
  165. case self::ORDER_SAAS_INTEGRAL:
  166. $exist_order_no = SaasIntegralOrder::find()->where(['order_no' => $order_no])->exists();
  167. break;
  168. case self::ORDER_SAAS_PROFIT_CASH:
  169. $exist_order_no = SaasProfitCash::find()->where(['order_no' => $order_no])->exists();
  170. break;
  171. case self::ORDER_ALIPAY_FOOD:
  172. $exist_order_no = FoodOrder::find()->where(['order_no' => $order_no])->exists();
  173. break;
  174. case self::STORE_ORDER_RECHARGE:
  175. $exist_order_no = StoreReOrder::find()->where(['order_no' => $order_no])->exists();
  176. break;
  177. case self::ORDER_ALLIANCE_MEMBER:
  178. $exist_order_no = BusinessMemberOrder::find()->where(['order_no' => $order_no])->exists();
  179. break;
  180. case self::ORDER_ALLIANCE:
  181. $exist_order_no = Order::find()->where(['order_no' => $order_no])->exists();
  182. case self::ORDER_ALLIANCE_PURCHASE:
  183. $exist_order_no = PurchaseOrder::find()->where(['order_no' => $order_no])->exists();
  184. case self::ORDER_PURCHASE_RE:
  185. $exist_order_no = \app\models\PurchaseReOrder::find()->where(['order_no' => $order_no])->exists();
  186. case self::LEAGUE_PRICE:
  187. $exist_order_no = \app\models\RechargeReOrder::find()->where(['order_no' => $order_no])->exists();
  188. case self::ADOPT_COST_ORDER:
  189. $exist_order_no = AdoptCostOrder::find()->where(['order_no' => $order_no])->exists();
  190. break;
  191. // case self::ORDER_INTEGRAL_COUPON:
  192. // $exist_order_no = IntegralCouponOrder::find()->where(['order_no' => $order_no])->exists();
  193. // break;
  194. // case self::ORDER_SCRATCH:
  195. // $exist_order_no = ScratchOrder::find()->where(['order_no' => $order_no])->exists();
  196. // break;
  197. // case self::ORDER_STEP:
  198. // $exist_order_no = \app\plugins\step\models\Order::find()->where(['order_no' => $order_no])->exists();
  199. // break;
  200. // case self::ORDER_POND:
  201. // $exist_order_no = \app\plugins\pond\models\models\Order::find()->where(['order_no' => $order_no])->exists();
  202. // break;
  203. // case self::ORDER_BARGAIN_REFUND:
  204. // $exist_order_no = BargainOrderRefund::find()->where(['order_refund_no' => $order_no])->exists();
  205. // break;
  206. case self::ALIPAY_ACTIVITY_DELIVERY:
  207. $exist_order_no = AlipayActivityDelivery::find()->where(['order_no' => $order_no])->exists();
  208. break;
  209. case self::ALIPAY_VOUCHAR_CODE:
  210. $exist_order_no = AlipayVoucherCode::find()->where(['order_no' => $order_no])->exists();
  211. default:;
  212. }
  213. if (!$exist_order_no) {
  214. break;
  215. }
  216. }
  217. return $order_no;
  218. }
  219. }