StoreOrderCreateServices.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\order;
  12. use app\services\activity\advance\StoreAdvanceServices;
  13. use app\services\activity\combination\StorePinkServices;
  14. use app\services\agent\AgentLevelServices;
  15. use app\services\activity\coupon\StoreCouponUserServices;
  16. use app\services\agent\DivisionServices;
  17. use app\services\product\product\StoreCategoryServices;
  18. use app\services\shipping\ShippingTemplatesFreeServices;
  19. use app\services\shipping\ShippingTemplatesRegionServices;
  20. use app\services\shipping\ShippingTemplatesServices;
  21. use app\services\user\UserInvoiceServices;
  22. use app\services\wechat\WechatUserServices;
  23. use app\services\BaseServices;
  24. use crmeb\exceptions\ApiException;
  25. use crmeb\exceptions\ApiStatusException;
  26. use crmeb\services\CacheService;
  27. use app\dao\order\StoreOrderDao;
  28. use app\services\user\UserServices;
  29. use app\services\user\UserBillServices;
  30. use app\services\user\UserAddressServices;
  31. use app\services\activity\bargain\StoreBargainServices;
  32. use app\services\activity\seckill\StoreSeckillServices;
  33. use app\services\system\store\SystemStoreServices;
  34. use app\services\activity\combination\StoreCombinationServices;
  35. use app\services\product\product\StoreProductServices;
  36. use think\facade\Cache;
  37. use think\facade\Config;
  38. use think\facade\Log;
  39. /**
  40. * 订单创建
  41. * Class StoreOrderCreateServices
  42. * @package app\services\order
  43. */
  44. class StoreOrderCreateServices extends BaseServices
  45. {
  46. /**
  47. * StoreOrderCreateServices constructor.
  48. * @param StoreOrderDao $dao
  49. */
  50. public function __construct(StoreOrderDao $dao)
  51. {
  52. $this->dao = $dao;
  53. }
  54. /**
  55. * 使用雪花算法生成订单ID
  56. * @return string
  57. * @throws \Exception
  58. */
  59. public function getNewOrderId(string $prefix = 'wx')
  60. {
  61. $snowflake = new \Godruoyi\Snowflake\Snowflake();
  62. if (Config::get('cache.default') == 'file') {
  63. //32位
  64. if (PHP_INT_SIZE == 4) {
  65. $id = abs($snowflake->id());
  66. } else {
  67. $id = $snowflake->setStartTimeStamp(strtotime('2022-01-01') * 1000)->id();
  68. }
  69. $replace = '';
  70. $chars = '0123456789';
  71. for ($i = 0; $i < 6; $i++) {
  72. $replace .= $chars[mt_rand(0, strlen($chars) - 1)];
  73. }
  74. $id = substr_replace($id, $replace, -6);
  75. } else {
  76. $is_callable = function ($currentTime) {
  77. $redis = Cache::store('redis');
  78. $swooleSequenceResolver = new \Godruoyi\Snowflake\RedisSequenceResolver($redis->handler());
  79. return $swooleSequenceResolver->sequence($currentTime);
  80. };
  81. //32位
  82. if (PHP_INT_SIZE == 4) {
  83. $id = abs($snowflake->setSequenceResolver($is_callable)->id());
  84. } else {
  85. $id = $snowflake->setStartTimeStamp(strtotime('2022-01-01') * 1000)->setSequenceResolver($is_callable)->id();
  86. }
  87. }
  88. return $prefix . $id;
  89. }
  90. /**
  91. * 核销订单生成核销码
  92. * @return false|string
  93. */
  94. public function getStoreCode()
  95. {
  96. list($msec, $sec) = explode(' ', microtime());
  97. $num = time() + mt_rand(10, 999999) . '' . substr($msec, 2, 3);//生成随机数
  98. if (strlen($num) < 12)
  99. $num = str_pad((string)$num, 12, 0, STR_PAD_RIGHT);
  100. else
  101. $num = substr($num, 0, 12);
  102. if ($this->dao->count(['verify_code' => $num])) {
  103. return $this->getStoreCode();
  104. }
  105. return $num;
  106. }
  107. /**
  108. * 创建订单
  109. * @param $uid
  110. * @param $key
  111. * @param $userInfo
  112. * @param $addressId
  113. * @param $payType
  114. * @param false $useIntegral
  115. * @param int $couponId
  116. * @param string $mark
  117. * @param int $combinationId
  118. * @param int $pinkId
  119. * @param int $seckillId
  120. * @param int $bargainId
  121. * @param int $shippingType
  122. * @param string $real_name
  123. * @param string $phone
  124. * @param int $storeId
  125. * @param false $news
  126. * @param int $advanceId
  127. * @param array $customForm
  128. * @param int $invoice_id
  129. * @return mixed
  130. * @throws \think\db\exception\DataNotFoundException
  131. * @throws \think\db\exception\DbException
  132. * @throws \think\db\exception\ModelNotFoundException
  133. * @author 吴汐
  134. * @email 442384644@qq.com
  135. * @date 2023/03/01
  136. */
  137. public function createOrder($uid, $key, $userInfo, $addressId, $payType, $useIntegral = false, $couponId = 0, $mark = '', $combinationId = 0, $pinkId = 0, $seckillId = 0, $bargainId = 0, $shippingType = 1, $real_name = '', $phone = '', $storeId = 0, $news = false, $advanceId = 0, $customForm = [], $invoice_id = 0, $is_gift = 0, $gift_mark = '', $lb_spread_uid = 0)
  138. {
  139. try {
  140. /** @var StoreOrderServices $orderService */
  141. $storeOrderServices = app()->make(StoreOrderServices::class);
  142. $bargainServices = app()->make(StoreBargainServices::class);
  143. $cartGroup = $storeOrderServices->getCacheOrderInfo($uid, $key);
  144. if (!$cartGroup) {
  145. throw new ApiException(410208);
  146. }
  147. //下单前砍价验证
  148. if ($bargainId) {
  149. $bargainServices->checkBargainUser((int)$bargainId, $uid);
  150. }
  151. if ($pinkId) {
  152. $pinkId = (int)$pinkId;
  153. /** @var StorePinkServices $pinkServices */
  154. $pinkServices = app()->make(StorePinkServices::class);
  155. if ($pinkServices->isPink($pinkId, $uid))
  156. throw new ApiStatusException('ORDER_EXIST', 410210, ['orderId' => $storeOrderServices->getStoreIdPink($pinkId, $uid)]);
  157. if ($storeOrderServices->getIsOrderPink($pinkId, $uid))
  158. throw new ApiStatusException('ORDER_EXIST', 410211, ['orderId' => $storeOrderServices->getStoreIdPink($pinkId, $uid)]);
  159. }
  160. $virtual_type = $cartGroup['cartInfo'][0]['productInfo']['virtual_type'] ?? 0;
  161. //下单前发票验证
  162. if ($invoice_id) {
  163. app()->make(UserInvoiceServices::class)->checkInvoice((int)$invoice_id, $uid);
  164. }
  165. /** @var StoreOrderComputedServices $computedServices */
  166. $computedServices = app()->make(StoreOrderComputedServices::class);
  167. $priceData = $computedServices->computedOrder($uid, $userInfo, $cartGroup, $addressId, $payType, $useIntegral, $couponId, true, $shippingType, $is_gift);
  168. /** @var WechatUserServices $wechatServices */
  169. $wechatServices = app()->make(WechatUserServices::class);
  170. /** @var UserAddressServices $addressServices */
  171. $addressServices = app()->make(UserAddressServices::class);
  172. if ($is_gift == 0) {
  173. if ($shippingType == 1 && $virtual_type == 0) {
  174. if (!$addressId) {
  175. throw new ApiException(410045);
  176. }
  177. if (!$addressInfo = $addressServices->getOne(['uid' => $uid, 'id' => $addressId, 'is_del' => 0]))
  178. throw new ApiException(410046);
  179. $addressInfo = $addressInfo->toArray();
  180. } else {
  181. if ((!$real_name || !$phone) && $virtual_type == 0) {
  182. throw new ApiException(410245);
  183. }
  184. $addressInfo['real_name'] = $real_name;
  185. $addressInfo['phone'] = $phone;
  186. $addressInfo['province'] = '';
  187. $addressInfo['city'] = '';
  188. $addressInfo['district'] = '';
  189. $addressInfo['detail'] = '';
  190. }
  191. } else {
  192. $addressInfo['real_name'] = '';
  193. $addressInfo['phone'] = '';
  194. $addressInfo['province'] = '';
  195. $addressInfo['city'] = '';
  196. $addressInfo['district'] = '';
  197. $addressInfo['detail'] = '';
  198. }
  199. $cartInfo = $cartGroup['cartInfo'];
  200. $priceGroup = $cartGroup['priceGroup'];
  201. $cartIds = [];
  202. $totalNum = 0;
  203. $gainIntegral = 0;
  204. $is_lb = 0;
  205. foreach ($cartInfo as $cart) {
  206. $cartIds[] = $cart['id'];
  207. $totalNum += $cart['cart_num'];
  208. if (!$seckillId) $seckillId = $cart['seckill_id'];
  209. if (!$bargainId) $bargainId = $cart['bargain_id'];
  210. if (!$combinationId) $combinationId = $cart['combination_id'];
  211. if (!$advanceId) $advanceId = $cart['advance_id'];
  212. $cartInfoGainIntegral = isset($cart['productInfo']['give_integral']) ? bcmul((string)$cart['cart_num'], (string)$cart['productInfo']['give_integral'], 0) : 0;
  213. $gainIntegral = bcadd((string)$gainIntegral, (string)$cartInfoGainIntegral, 0);
  214. if ($cart['productInfo']['is_lb']==1){
  215. $is_lb = 1;
  216. }
  217. // @file_put_contents('quanju.txt', json_encode($cart) . "-购物车\r\n", 8);
  218. }
  219. if (count($cartInfo) == 1 && isset($cartInfo[0]['productInfo']['presale']) && $cartInfo[0]['productInfo']['presale'] == 1) {
  220. $advance_id = $cartInfo[0]['product_id'];
  221. } else {
  222. $advance_id = 0;
  223. }
  224. $deduction = $seckillId || $bargainId || $combinationId;
  225. if ($deduction) {
  226. $couponId = 0;
  227. $gainIntegral = 0;
  228. $useIntegral = false;
  229. }
  230. //$shipping_type = 1 快递发货 $shipping_type = 2 门店自提
  231. $storeSelfMention = sys_config('store_self_mention') ?? 0;
  232. if (!$storeSelfMention) $shippingType = 1;
  233. if ($is_gift == 1) $shippingType = 0;
  234. $orderInfo = [
  235. 'uid' => $uid,
  236. 'order_id' => $this->getNewOrderId('cp'),
  237. 'real_name' => $addressInfo['real_name'],
  238. 'user_phone' => $addressInfo['phone'],
  239. 'user_address' => $addressInfo['province'] . ' ' . $addressInfo['city'] . ' ' . $addressInfo['district'] . ' ' . $addressInfo['detail'],
  240. 'cart_id' => $cartIds,
  241. 'total_num' => $totalNum,
  242. 'total_price' => $priceGroup['totalPrice'],
  243. 'total_postage' => $shippingType == 1 ? $priceGroup['storePostage'] : 0,
  244. 'coupon_id' => $couponId,
  245. 'coupon_price' => $priceData['coupon_price'],
  246. 'pay_price' => $priceData['pay_price'],
  247. 'pay_postage' => $priceData['pay_postage'],
  248. 'deduction_price' => $priceData['deduction_price'],
  249. 'gift_price' => $priceData['gift_price'],
  250. 'paid' => 0,
  251. 'pay_type' => $payType,
  252. 'use_integral' => $priceData['usedIntegral'],
  253. 'gain_integral' => $gainIntegral,
  254. 'mark' => htmlspecialchars($mark),
  255. 'combination_id' => $combinationId,
  256. 'pink_id' => $pinkId,
  257. 'seckill_id' => $seckillId,
  258. 'bargain_id' => $bargainId,
  259. 'advance_id' => $advance_id,
  260. 'cost' => $priceGroup['costPrice'],
  261. 'add_time' => time(),
  262. 'unique' => $key,
  263. 'shipping_type' => $shippingType,
  264. 'channel_type' => $userInfo['user_type'],
  265. 'province' => strval($userInfo['user_type'] == 'wechat' || $userInfo['user_type'] == 'routine' ? $wechatServices->value(['uid' => $uid, 'user_type' => $userInfo['user_type']], 'province') : ''),
  266. 'spread_uid' => 0,
  267. 'spread_two_uid' => 0,
  268. 'virtual_type' => $virtual_type,
  269. 'is_gift' => $is_gift,
  270. 'gift_mark' => $gift_mark,
  271. 'pay_uid' => $uid,
  272. 'custom_form' => json_encode($customForm),
  273. 'division_id' => $userInfo['division_id'],
  274. 'agent_id' => $userInfo['agent_id'],
  275. 'staff_id' => $userInfo['staff_id'],
  276. 'lb_spread_uid' => $lb_spread_uid,
  277. 'is_lb' => $is_lb
  278. ];
  279. if ($shippingType == 2) {
  280. $orderInfo['verify_code'] = $this->getStoreCode();
  281. /** @var SystemStoreServices $storeServices */
  282. $storeServices = app()->make(SystemStoreServices::class);
  283. $orderInfo['store_id'] = $storeServices->getStoreDispose($storeId, 'id');
  284. if (!$orderInfo['store_id']) {
  285. throw new ApiException(410247);
  286. }
  287. }
  288. /** @var StoreOrderCartInfoServices $cartServices */
  289. $cartServices = app()->make(StoreOrderCartInfoServices::class);
  290. $priceData['coupon_id'] = $couponId;
  291. $order = $this->transaction(function () use ($cartIds, $orderInfo, $cartInfo, $key, $userInfo, $useIntegral, $priceData, $combinationId, $seckillId, $bargainId, $cartServices, $uid, $addressId, $advanceId) {
  292. //创建订单
  293. $order = $this->dao->save($orderInfo);
  294. if (!$order) {
  295. throw new ApiException(410200);
  296. }
  297. //记录自提人电话和姓名
  298. /** @var UserServices $userService */
  299. $userService = app()->make(UserServices::class);
  300. $realName = $userService->value(['uid' => $uid], 'real_name');
  301. if ($realName == '') $userService->update(['uid' => $uid], ['real_name' => $orderInfo['real_name'], 'record_phone' => $orderInfo['user_phone']]);
  302. //积分抵扣
  303. if ($priceData['usedIntegral'] > 0) {
  304. $this->deductIntegral($userInfo, $useIntegral, $priceData, (int)$userInfo['uid'], $order['id']);
  305. }
  306. //扣库存
  307. $this->decGoodsStock($cartInfo, $combinationId, $seckillId, $bargainId, $advanceId);
  308. //保存购物车商品信息
  309. $cartServices->setCartInfo($order['id'], $uid, $cartInfo);
  310. return $order;
  311. });
  312. //创建开票数据
  313. if ($invoice_id) {
  314. app()->make(StoreOrderInvoiceServices::class)->makeUp($uid, $order['order_id'], (int)$invoice_id);
  315. }
  316. // 订单创建成功后置事件
  317. event('OrderCreateAfterListener', [$order, compact('cartInfo', 'priceData', 'addressId', 'cartIds', 'news'), $uid, $key, $combinationId, $seckillId, $bargainId]);
  318. // 推送订单
  319. event('OutPushListener', ['order_create_push', ['order_id' => (int)$order['id']]]);
  320. //自定义事件-订单创建事件
  321. event('CustomEventListener', ['order_create', [
  322. 'uid' => $uid,
  323. 'id' => (int)$order['id'],
  324. 'order_id' => $order['order_id'],
  325. 'real_name' => $order['real_name'],
  326. 'user_phone' => $order['user_phone'],
  327. 'user_address' => $order['user_address'],
  328. 'total_num' => $order['total_num'],
  329. 'pay_price' => $order['pay_price'],
  330. 'pay_postage' => $order['pay_postage'],
  331. 'deduction_price' => $order['deduction_price'],
  332. 'coupon_price' => $order['coupon_price'],
  333. 'store_name' => app()->make(StoreOrderCartInfoServices::class)->getCarIdByProductTitle((int)$order['id']),
  334. 'add_time' => date('Y-m-d H:i:s', $order['add_time']),
  335. ]]);
  336. return $order;
  337. } catch (\Exception $e) {
  338. @file_put_contents('quanju4.txt', $e->getMessage() . "-创建订单报错内容\r\n", 8);
  339. @file_put_contents('quanju4.txt', $e->getFile() . "-文件\r\n", 8);
  340. @file_put_contents('quanju4.txt', $e->getLine() . "-位置\r\n", 8);
  341. }
  342. }
  343. /**
  344. * 抵扣积分
  345. * @param array $userInfo
  346. * @param bool $useIntegral
  347. * @param array $priceData
  348. * @param int $uid
  349. * @param string $key
  350. */
  351. public function deductIntegral(array $userInfo, bool $useIntegral, array $priceData, int $uid, $orderId)
  352. {
  353. $res2 = true;
  354. if ($useIntegral && $userInfo['integral'] > 0) {
  355. /** @var UserServices $userServices */
  356. $userServices = app()->make(UserServices::class);
  357. if (!$priceData['SurplusIntegral']) {
  358. $res2 = false !== $userServices->update($uid, ['integral' => 0]);
  359. } else {
  360. $res2 = false !== $userServices->bcDec($userInfo['uid'], 'integral', $priceData['usedIntegral'], 'uid');
  361. }
  362. /** @var UserBillServices $userBillServices */
  363. $userBillServices = app()->make(UserBillServices::class);
  364. $res3 = $userBillServices->income('deduction', $uid, [
  365. 'number' => $priceData['usedIntegral'],
  366. 'deductionPrice' => $priceData['deduction_price']
  367. ], $userInfo['integral'] - $priceData['usedIntegral'], $orderId);
  368. $res2 = $res2 && false != $res3;
  369. }
  370. if (!$res2) {
  371. throw new ApiException(410227);
  372. }
  373. }
  374. /**
  375. * 扣库存
  376. * @param array $cartInfo
  377. * @param int $combinationId
  378. * @param int $seckillId
  379. * @param int $bargainId
  380. */
  381. public function decGoodsStock(array $cartInfo, int $combinationId, int $seckillId, int $bargainId, int $advanceId)
  382. {
  383. $res5 = true;
  384. /** @var StoreProductServices $services */
  385. $services = app()->make(StoreProductServices::class);
  386. /** @var StoreSeckillServices $seckillServices */
  387. $seckillServices = app()->make(StoreSeckillServices::class);
  388. /** @var StoreCombinationServices $pinkServices */
  389. $pinkServices = app()->make(StoreCombinationServices::class);
  390. /** @var StoreBargainServices $bargainServices */
  391. $bargainServices = app()->make(StoreBargainServices::class);
  392. /** @var StoreAdvanceServices $advanceServices */
  393. $advanceServices = app()->make(StoreAdvanceServices::class);
  394. try {
  395. foreach ($cartInfo as $cart) {
  396. //减库存加销量
  397. if ($combinationId) $res5 = $res5 && $pinkServices->decCombinationStock((int)$cart['cart_num'], $combinationId, isset($cart['productInfo']['attrInfo']) ? $cart['productInfo']['attrInfo']['unique'] : '');
  398. else if ($seckillId) $res5 = $res5 && $seckillServices->decSeckillStock((int)$cart['cart_num'], $seckillId, isset($cart['productInfo']['attrInfo']) ? $cart['productInfo']['attrInfo']['unique'] : '');
  399. else if ($bargainId) $res5 = $res5 && $bargainServices->decBargainStock((int)$cart['cart_num'], $bargainId, isset($cart['productInfo']['attrInfo']) ? $cart['productInfo']['attrInfo']['unique'] : '');
  400. else if ($advanceId) $res5 = $res5 && $advanceServices->decAdvanceStock((int)$cart['cart_num'], $advanceId, isset($cart['productInfo']['attrInfo']) ? $cart['productInfo']['attrInfo']['unique'] : '');
  401. else $res5 = $res5 && $services->decProductStock((int)$cart['cart_num'], (int)$cart['productInfo']['id'], isset($cart['productInfo']['attrInfo']) ? $cart['productInfo']['attrInfo']['unique'] : '');
  402. }
  403. if (!$res5) {
  404. throw new ApiException(410238);
  405. }
  406. } catch (\Throwable $e) {
  407. throw new ApiException(410238);
  408. }
  409. }
  410. /**
  411. * 订单数据创建之后的商品实际金额计算,佣金计算,优惠折扣计算,设置默认地址,清理购物车
  412. * @param $order
  413. * @param array $group
  414. * @param $activity
  415. */
  416. public function orderCreateAfter($order, array $group, $activity)
  417. {
  418. /** @var UserAddressServices $addressServices */
  419. $addressServices = app()->make(UserAddressServices::class);
  420. //设置用户默认地址
  421. if (!$addressServices->be(['is_default' => 1, 'uid' => $order['uid']])) {
  422. $addressServices->setDefaultAddress($group['addressId'], $order['uid']);
  423. $province = $addressServices->value(['id' => $group['addressId']], 'province') ?? '';
  424. app()->make(WechatUserServices::class)->update(['uid' => $order['uid']], ['province' => $province]);
  425. }
  426. //删除购物车
  427. if ($group['news']) {
  428. array_map(function ($key) {
  429. CacheService::delete($key);
  430. }, $group['cartIds']);
  431. } else {
  432. /** @var StoreCartServices $cartServices */
  433. $cartServices = app()->make(StoreCartServices::class);
  434. $cartServices->deleteCartStatus($group['cartIds']);
  435. }
  436. $uid = (int)$order['uid'];
  437. $orderId = (int)$order['id'];
  438. try {
  439. $cartInfo = $group['cartInfo'] ?? [];
  440. $priceData = $group['priceData'] ?? [];
  441. $addressId = $group['addressId'] ?? 0;
  442. $spread_ids = [];
  443. /** @var StoreOrderCreateServices $createService */
  444. $createService = app()->make(StoreOrderCreateServices::class);
  445. if ($cartInfo && $priceData) {
  446. /** @var StoreOrderCartInfoServices $cartServices */
  447. $cartServices = app()->make(StoreOrderCartInfoServices::class);
  448. [$cartInfo, $spread_ids] = $createService->computeOrderProductTruePrice($cartInfo, $priceData, $addressId, $uid, $order);
  449. $cartServices->updateCartInfo($orderId, $cartInfo);
  450. }
  451. $orderData = [];
  452. $spread_uid = $spread_two_uid = 0;
  453. /** @var UserServices $userServices */
  454. $userServices = app()->make(UserServices::class);
  455. if ($spread_ids) {
  456. [$spread_uid, $spread_two_uid] = $spread_ids;
  457. $orderData['spread_uid'] = $spread_uid;
  458. $orderData['spread_two_uid'] = $spread_two_uid;
  459. } else {
  460. $spread_uid = $userServices->getSpreadUid($uid);
  461. $orderData = ['spread_uid' => 0, 'spread_two_uid' => 0];
  462. if ($spread_uid) {
  463. $orderData['spread_uid'] = $spread_uid;
  464. }
  465. if ($spread_uid > 0 && sys_config('brokerage_level') == 2) {
  466. $spread_two_uid = $userServices->getSpreadUid($spread_uid, [], false);
  467. if ($spread_two_uid) {
  468. $orderData['spread_two_uid'] = $spread_two_uid;
  469. }
  470. }
  471. }
  472. $isCommission = 0;
  473. if ($order['combination_id']) {
  474. //检测拼团是否参与返佣
  475. $isCommission = app()->make(StoreCombinationServices::class)->value(['id' => $order['combination_id']], 'is_commission');
  476. }
  477. if ($order['seckill_id']) {
  478. //检测秒杀是否参与返佣
  479. $isCommission = app()->make(StoreSeckillServices::class)->value(['id' => $order['seckill_id']], 'is_commission');
  480. }
  481. if ($order['bargain_id']) {
  482. //检测砍价是否参与返佣
  483. $isCommission = app()->make(StoreBargainServices::class)->value(['id' => $order['bargain_id']], 'is_commission');
  484. }
  485. if ($cartInfo && (!$activity || $isCommission)) {
  486. /** @var StoreOrderComputedServices $orderComputed */
  487. $orderComputed = app()->make(StoreOrderComputedServices::class);
  488. if ($userServices->checkUserPromoter($spread_uid)) $orderData['one_brokerage'] = $orderComputed->getOrderSumPrice($cartInfo, 'one_brokerage', false);
  489. if ($userServices->checkUserPromoter($spread_two_uid)) $orderData['two_brokerage'] = $orderComputed->getOrderSumPrice($cartInfo, 'two_brokerage', false);
  490. $orderData['staff_brokerage'] = $orderComputed->getOrderSumPrice($cartInfo, 'staff_brokerage', false);
  491. $orderData['agent_brokerage'] = $orderComputed->getOrderSumPrice($cartInfo, 'agent_brokerage', false);
  492. $orderData['division_brokerage'] = $orderComputed->getOrderSumPrice($cartInfo, 'division_brokerage', false);
  493. }
  494. $createService->update(['id' => $orderId], $orderData);
  495. } catch (\Throwable $e) {
  496. throw new ApiException('计算订单实际优惠、积分、邮费、佣金失败,原因:' . $e->getMessage());
  497. }
  498. }
  499. /**
  500. * 计算订单每个商品真实付款价格
  501. * @param array $cartInfo
  502. * @param array $priceData
  503. * @param $addressId
  504. * @param int $uid
  505. * @return array
  506. */
  507. public function computeOrderProductTruePrice(array $cartInfo, array $priceData, $addressId, int $uid, $orderInfo)
  508. {
  509. //统一放入默认数据
  510. foreach ($cartInfo as &$cart) {
  511. $cart['use_integral'] = 0;
  512. $cart['integral_price'] = 0.00;
  513. $cart['coupon_price'] = 0.00;
  514. }
  515. try {
  516. $cartInfo = $this->computeOrderProductCoupon($cartInfo, $priceData);
  517. $cartInfo = $this->computeOrderProductIntegral($cartInfo, $priceData);
  518. } catch (\Throwable $e) {
  519. Log::error('订单商品结算失败,File:' . $e->getFile() . ',Line:' . $e->getLine() . ',Message:' . $e->getMessage());
  520. throw new ApiException(410248);
  521. }
  522. //truePice实际支付单价(存在)
  523. //几件商品总体优惠 以及积分抵扣金额
  524. foreach ($cartInfo as &$cart) {
  525. $coupon_price = $cart['coupon_price'] ?? 0;
  526. $integral_price = $cart['integral_price'] ?? 0;
  527. $cart['sum_true_price'] = bcmul((string)$cart['truePrice'], (string)$cart['cart_num'], 2);
  528. if ($coupon_price) {
  529. $cart['sum_true_price'] = bcsub((string)$cart['sum_true_price'], (string)$coupon_price, 2);
  530. $uni_coupon_price = (string)bcdiv((string)$coupon_price, (string)$cart['cart_num'], 4);
  531. $cart['truePrice'] = $cart['truePrice'] > $uni_coupon_price ? bcsub((string)$cart['truePrice'], $uni_coupon_price, 2) : 0;
  532. }
  533. if ($integral_price) {
  534. $cart['sum_true_price'] = bcsub((string)$cart['sum_true_price'], (string)$integral_price, 2);
  535. $uni_integral_price = (string)bcdiv((string)$integral_price, (string)$cart['cart_num'], 4);
  536. $cart['truePrice'] = $cart['truePrice'] > $uni_integral_price ? bcsub((string)$cart['truePrice'], $uni_integral_price, 2) : 0;
  537. }
  538. if ($cart['sum_true_price'] < 0) $cart['sum_true_price'] = '0.00';
  539. }
  540. try {
  541. [$cartInfo, $spread_ids] = $this->computeOrderProductBrokerage($uid, $cartInfo);
  542. } catch (\Throwable $e) {
  543. Log::error('订单商品结算失败,File:' . $e->getFile() . ',Line:' . $e->getLine() . ',Message:' . $e->getMessage());
  544. throw new ApiException(410248);
  545. }
  546. return [$cartInfo, $spread_ids];
  547. }
  548. /**
  549. * 计算每个商品实际支付运费
  550. * @param array $cartInfo
  551. * @param array $priceData
  552. * @return array
  553. */
  554. public function computeOrderProductPostage(array $cartInfo, array $priceData, $addressId)
  555. {
  556. $storePostage = $priceData['pay_postage'] ?? 0;
  557. if ($storePostage) {
  558. /** @var UserAddressServices $addressServices */
  559. $addressServices = app()->make(UserAddressServices::class);
  560. $addr = $addressServices->getAddress($addressId);
  561. if ($addr) {
  562. $addr = $addr->toArray();
  563. //按照运费模板计算每个运费模板下商品的件数/重量/体积以及总金额 按照首重倒序排列
  564. $cityId = $addr['city_id'] ?? 0;
  565. $tempIds[] = 1;
  566. foreach ($cartInfo as $key_c => $item_c) {
  567. $tempIds[] = $item_c['productInfo']['temp_id'];
  568. }
  569. $tempIds = array_unique($tempIds);
  570. /** @var ShippingTemplatesServices $shippServices */
  571. $shippServices = app()->make(ShippingTemplatesServices::class);
  572. $temp = $shippServices->getShippingColumn(['id' => $tempIds], 'type,appoint', 'id');
  573. /** @var ShippingTemplatesRegionServices $regionServices */
  574. $regionServices = app()->make(ShippingTemplatesRegionServices::class);
  575. $regions = $regionServices->getTempRegionList($tempIds, [$cityId, 0], 'temp_id,first,first_price,continue,continue_price', 'temp_id');
  576. $temp_num = [];
  577. foreach ($cartInfo as $cart) {
  578. $tempId = $cart['productInfo']['temp_id'] ?? 1;
  579. $type = $temp[$tempId]['type'] ?? $temp[1]['type'];
  580. if ($type == 1) {
  581. $num = $cart['cart_num'];
  582. } elseif ($type == 2) {
  583. $num = $cart['cart_num'] * $cart['productInfo']['attrInfo']['weight'];
  584. } else {
  585. $num = $cart['cart_num'] * $cart['productInfo']['attrInfo']['volume'];
  586. }
  587. $region = $regions[$tempId] ?? $regions[1];
  588. if (!isset($temp_num[$cart['productInfo']['temp_id']])) {
  589. $temp_num[$cart['productInfo']['temp_id']]['cart_id'][] = $cart['id'];
  590. $temp_num[$cart['productInfo']['temp_id']]['number'] = $num;
  591. $temp_num[$cart['productInfo']['temp_id']]['type'] = $type;
  592. $temp_num[$cart['productInfo']['temp_id']]['price'] = bcmul($cart['cart_num'], $cart['truePrice'], 2);
  593. $temp_num[$cart['productInfo']['temp_id']]['first'] = $region['first'];
  594. $temp_num[$cart['productInfo']['temp_id']]['first_price'] = $region['first_price'];
  595. $temp_num[$cart['productInfo']['temp_id']]['continue'] = $region['continue'];
  596. $temp_num[$cart['productInfo']['temp_id']]['continue_price'] = $region['continue_price'];
  597. $temp_num[$cart['productInfo']['temp_id']]['temp_id'] = $cart['productInfo']['temp_id'];
  598. $temp_num[$cart['productInfo']['temp_id']]['city_id'] = $addr['city_id'];
  599. } else {
  600. $temp_num[$cart['productInfo']['temp_id']]['cart_id'][] = $cart['id'];
  601. $temp_num[$cart['productInfo']['temp_id']]['number'] += $num;
  602. $temp_num[$cart['productInfo']['temp_id']]['price'] += bcmul($cart['cart_num'], $cart['truePrice'], 2);
  603. }
  604. }
  605. $cartInfo = array_combine(array_column($cartInfo, 'id'), $cartInfo);
  606. /** @var ShippingTemplatesFreeServices $freeServices */
  607. $freeServices = app()->make(ShippingTemplatesFreeServices::class);
  608. foreach ($temp_num as $k => $v) {
  609. if (isset($temp[$v['temp_id']]['appoint']) && $temp[$v['temp_id']]['appoint']) {
  610. if ($freeServices->isFree($v['temp_id'], $v['city_id'], $v['number'], $v['price'], $v['type'])) {
  611. //免运费
  612. foreach ($v['cart_id'] as $c_id) {
  613. if (isset($cartInfo[$c_id])) $cartInfo[$c_id]['postage_price'] = 0.00;
  614. }
  615. }
  616. }
  617. }
  618. $count = 0;
  619. $compute_price = 0.00;
  620. $total_price = 0;
  621. $postage_price = 0.00;
  622. foreach ($cartInfo as &$cart) {
  623. if (isset($cart['postage_price'])) {//免运费
  624. continue;
  625. }
  626. $total_price = bcadd((string)$total_price, (string)bcmul((string)$cart['truePrice'], (string)$cart['cart_num'], 4), 2);
  627. $count++;
  628. }
  629. foreach ($cartInfo as &$cart) {
  630. if (isset($cart['postage_price'])) {//免运费
  631. continue;
  632. }
  633. if ($count > 1) {
  634. $postage_price = bcmul((string)bcdiv((string)bcmul((string)$cart['cart_num'], (string)$cart['truePrice'], 4), (string)$total_price, 4), (string)$storePostage, 2);
  635. $compute_price = bcadd((string)$compute_price, (string)$postage_price, 2);
  636. } else {
  637. $postage_price = bcsub((string)$storePostage, $compute_price, 2);
  638. }
  639. $cart['postage_price'] = $postage_price;
  640. $count--;
  641. }
  642. $cartInfo = array_merge($cartInfo);
  643. }
  644. }
  645. //保证不进运费模版计算的购物车商品postage_price字段有值
  646. foreach ($cartInfo as &$item) {
  647. if (!isset($item['postage_price'])) $item['postage_price'] = 0.00;
  648. }
  649. return $cartInfo;
  650. }
  651. /**
  652. * 计算订单商品积分实际抵扣金额
  653. * @param array $cartInfo
  654. * @param array $priceData
  655. * @return array
  656. */
  657. public function computeOrderProductIntegral(array $cartInfo, array $priceData)
  658. {
  659. $usedIntegral = $priceData['usedIntegral'] ?? 0;
  660. $deduction_price = $priceData['deduction_price'] ?? 0;
  661. if ($deduction_price) {
  662. $count = 0;
  663. $total_price = 0.00;
  664. $compute_price = 0.00;
  665. $integral_price = 0.00;
  666. $use_integral = 0;
  667. $compute_integral = 0;
  668. foreach ($cartInfo as $cart) {
  669. $total_price = bcadd((string)$total_price, (string)bcmul((string)$cart['truePrice'], (string)$cart['cart_num'], 4), 2);
  670. $count++;
  671. }
  672. foreach ($cartInfo as &$cart) {
  673. if ($count > 1) {
  674. $integral_price = bcmul((string)bcdiv((string)bcmul((string)$cart['cart_num'], (string)$cart['truePrice'], 4), (string)$total_price, 4), (string)$deduction_price, 2);
  675. $compute_price = bcadd((string)$compute_price, (string)$integral_price, 2);
  676. $use_integral = bcmul((string)bcdiv((string)bcmul((string)$cart['cart_num'], (string)$cart['truePrice'], 4), (string)$total_price, 4), (string)$usedIntegral, 0);
  677. $compute_integral = bcadd((string)$compute_integral, $use_integral, 0);
  678. } else {
  679. $integral_price = bcsub((string)$deduction_price, $compute_price, 2);
  680. $use_integral = bcsub((string)$usedIntegral, $compute_integral, 0);
  681. }
  682. $count--;
  683. $cart['integral_price'] = $integral_price;
  684. $cart['use_integral'] = $use_integral;
  685. }
  686. }
  687. return $cartInfo;
  688. }
  689. /**
  690. * 计算订单商品优惠券实际抵扣金额
  691. * @param array $cartInfo
  692. * @param array $priceData
  693. * @return array
  694. */
  695. public function computeOrderProductCoupon(array $cartInfo, array $priceData)
  696. {
  697. if ($priceData['coupon_id'] && $priceData['coupon_price'] ?? 0) {
  698. $count = 0;
  699. $total_price = 0.00;
  700. $compute_price = 0.00;
  701. $coupon_price = 0.00;
  702. /** @var StoreCouponUserServices $couponServices */
  703. $couponServices = app()->make(StoreCouponUserServices::class);
  704. $couponInfo = $couponServices->getOne(['id' => $priceData['coupon_id']], '*', ['issue']);
  705. if ($couponInfo) {
  706. $type = $couponInfo['applicable_type'] ?? 0;
  707. $counpon_id = $couponInfo['id'];
  708. switch ($type) {
  709. case 0:
  710. case 3:
  711. foreach ($cartInfo as $cart) {
  712. $total_price = bcadd((string)$total_price, (string)bcmul((string)$cart['truePrice'], (string)$cart['cart_num'], 4), 2);
  713. $count++;
  714. }
  715. foreach ($cartInfo as &$cart) {
  716. if ($count > 1) {
  717. $coupon_price = bcmul((string)bcdiv((string)bcmul((string)$cart['cart_num'], (string)$cart['truePrice'], 4), (string)$total_price, 4), (string)$couponInfo['coupon_price'], 2);
  718. $compute_price = bcadd((string)$compute_price, (string)$coupon_price, 2);
  719. } else {
  720. $coupon_price = bcsub((string)$couponInfo['coupon_price'], $compute_price, 2);
  721. }
  722. $cart['coupon_price'] = $coupon_price;
  723. $cart['coupon_id'] = $counpon_id;
  724. $count--;
  725. }
  726. break;
  727. case 1://品类券
  728. /** @var StoreCategoryServices $storeCategoryServices */
  729. $storeCategoryServices = app()->make(StoreCategoryServices::class);
  730. $coupon_category = explode(',', (string)$couponInfo['category_id']);
  731. $category_ids = $storeCategoryServices->getAllById($coupon_category);
  732. if ($category_ids) {
  733. $cateIds = array_column($category_ids, 'id');
  734. foreach ($cartInfo as $cart) {
  735. if (isset($cart['productInfo']['cate_id']) && array_intersect(explode(',', $cart['productInfo']['cate_id']), $cateIds)) {
  736. $total_price = bcadd((string)$total_price, (string)bcmul((string)$cart['truePrice'], (string)$cart['cart_num'], 4), 2);
  737. $count++;
  738. }
  739. }
  740. foreach ($cartInfo as &$cart) {
  741. $cart['coupon_id'] = 0;
  742. $cart['coupon_price'] = 0;
  743. if (isset($cart['productInfo']['cate_id']) && array_intersect(explode(',', $cart['productInfo']['cate_id']), $cateIds)) {
  744. if ($count > 1) {
  745. $coupon_price = bcmul((string)bcdiv((string)bcmul((string)$cart['cart_num'], (string)$cart['truePrice'], 4), (string)$total_price, 4), (string)$couponInfo['coupon_price'], 2);
  746. $compute_price = bcadd((string)$compute_price, (string)$coupon_price, 2);
  747. } else {
  748. $coupon_price = bcsub((string)$couponInfo['coupon_price'], $compute_price, 2);
  749. }
  750. $cart['coupon_id'] = $counpon_id;
  751. $cart['coupon_price'] = $coupon_price;
  752. $count--;
  753. }
  754. }
  755. }
  756. break;
  757. case 2://商品劵
  758. foreach ($cartInfo as $cart) {
  759. if (isset($cart['product_id']) && in_array($cart['product_id'], explode(',', $couponInfo['product_id']))) {
  760. $total_price = bcadd((string)$total_price, (string)bcmul((string)$cart['truePrice'], (string)$cart['cart_num'], 4), 2);
  761. $count++;
  762. }
  763. }
  764. foreach ($cartInfo as &$cart) {
  765. $cart['coupon_id'] = 0;
  766. $cart['coupon_price'] = 0;
  767. if (isset($cart['product_id']) && in_array($cart['product_id'], explode(',', $couponInfo['product_id']))) {
  768. if ($count > 1) {
  769. $coupon_price = bcmul((string)bcdiv((string)bcmul((string)$cart['cart_num'], (string)$cart['truePrice'], 4), (string)$total_price, 4), (string)$couponInfo['coupon_price'], 2);
  770. $compute_price = bcadd((string)$compute_price, (string)$coupon_price, 2);
  771. } else {
  772. $coupon_price = bcsub((string)$couponInfo['coupon_price'], $compute_price, 2);
  773. }
  774. $cart['coupon_id'] = $counpon_id;
  775. $cart['coupon_price'] = $coupon_price;
  776. $count--;
  777. }
  778. }
  779. break;
  780. }
  781. }
  782. }
  783. return $cartInfo;
  784. }
  785. /**
  786. * 计算实际佣金
  787. * @param int $uid
  788. * @param array $cartInfo
  789. * @return array
  790. * @throws \think\db\exception\DataNotFoundException
  791. * @throws \think\db\exception\DbException
  792. * @throws \think\db\exception\ModelNotFoundException
  793. */
  794. public function computeOrderProductBrokerage(int $uid, array $cartInfo)
  795. {
  796. [$storeBrokerageRatio, $storeBrokerageTwo, $spread_one_uid, $spread_two_uid] = $this->getSpreadDate($uid);
  797. /** @var DivisionServices $divisionService */
  798. $divisionService = app()->make(DivisionServices::class);
  799. [$storeBrokerageRatio, $storeBrokerageTwo, $staffPercent, $agentPercent, $divisionPercent] = $divisionService->getDivisionPercent($uid, $storeBrokerageRatio, $storeBrokerageTwo, sys_config('is_self_brokerage', 0));
  800. foreach ($cartInfo as &$cart) {
  801. $oneBrokerage = '0';//一级返佣金额
  802. $twoBrokerage = '0';//二级返佣金额
  803. $staffBrokerage = '0';//店员返佣金额
  804. $agentBrokerage = '0';//代理商返佣金额
  805. $divisionBrokerage = '0';//事业部返佣金额
  806. $cartNum = (string)$cart['cart_num'] ?? '0';
  807. if (isset($cart['productInfo'])) {
  808. $productInfo = $cart['productInfo'];
  809. //计算商品金额
  810. if (sys_config('user_brokerage_type') == 1) {
  811. //按照实际支付价格返佣
  812. $price = bcmul((string)bcadd((string)$cart['truePrice'], (string)$cart['postage_price'], 2), $cartNum, 4);
  813. } else {
  814. //按照商品价格返佣
  815. if (isset($productInfo['attrInfo'])) {
  816. $price = bcmul((string)($productInfo['attrInfo']['price'] ?? '0'), $cartNum, 4);
  817. } else {
  818. $price = bcmul((string)($productInfo['price'] ?? '0'), $cartNum, 4);
  819. }
  820. }
  821. //指定返佣金额
  822. if (isset($productInfo['is_sub']) && $productInfo['is_sub'] == 1) {
  823. $oneBrokerage = bcmul((string)($productInfo['attrInfo']['brokerage'] ?? '0'), $cartNum, 2);
  824. $twoBrokerage = bcmul((string)($productInfo['attrInfo']['brokerage_two'] ?? '0'), $cartNum, 2);
  825. } else {
  826. if ($price) {
  827. //一级返佣比例 小于等于零时直接返回 不返佣
  828. if ($storeBrokerageRatio > 0) {
  829. //计算获取一级返佣比例
  830. $brokerageRatio = bcdiv($storeBrokerageRatio, 100, 4);
  831. $oneBrokerage = bcmul((string)$price, (string)$brokerageRatio, 2);
  832. }
  833. //二级返佣比例小于等于0 直接返回
  834. if ($storeBrokerageTwo > 0) {
  835. //计算获取二级返佣比例
  836. $brokerageTwo = bcdiv($storeBrokerageTwo, 100, 4);
  837. $twoBrokerage = bcmul((string)$price, (string)$brokerageTwo, 2);
  838. }
  839. }
  840. $staffBrokerage = bcmul((string)$price, (string)bcdiv($staffPercent, 100, 4), 2);
  841. $agentBrokerage = bcmul((string)$price, (string)bcdiv($agentPercent, 100, 4), 2);
  842. $divisionBrokerage = bcmul((string)$price, (string)bcdiv($divisionPercent, 100, 4), 2);
  843. }
  844. }
  845. $cart['one_brokerage'] = $oneBrokerage;
  846. $cart['two_brokerage'] = $twoBrokerage;
  847. $cart['staff_brokerage'] = $staffBrokerage;
  848. $cart['agent_brokerage'] = $agentBrokerage;
  849. $cart['division_brokerage'] = $divisionBrokerage;
  850. }
  851. return [$cartInfo, [$spread_one_uid, $spread_two_uid]];
  852. }
  853. /**
  854. * 获取计算好的佣金比例以及返佣人员uid
  855. * @param int $uid
  856. * @return array|int[]
  857. * @throws \think\db\exception\DataNotFoundException
  858. * @throws \think\db\exception\DbException
  859. * @throws \think\db\exception\ModelNotFoundException
  860. * @author: 吴汐
  861. * @email: 442384644@qq.com
  862. * @date: 2023/10/8
  863. */
  864. public function getSpreadDate(int $uid)
  865. {
  866. //商城分销是否开启,用户uid是否存在,全部返回0
  867. if (!sys_config('brokerage_func_status') || !$uid) {
  868. return [0, 0, 0, 0];
  869. }
  870. //获取用户信息,获取不到全部返回0
  871. /** @var UserServices $userServices */
  872. $userServices = app()->make(UserServices::class);
  873. $userInfo = $userServices->getUserInfo($uid);
  874. if (!$userInfo) {
  875. return [0, 0, 0, 0];
  876. }
  877. //获取系统一二级分佣比例
  878. $storeBrokerageRatio = sys_config('store_brokerage_ratio') != '' ? sys_config('store_brokerage_ratio') : 0;
  879. $storeBrokerageTwo = sys_config('store_brokerage_two') != '' ? sys_config('store_brokerage_two') : 0;
  880. //获取上级和上上级的uid,开启自购获取自己和上级的uid
  881. $spread_one_uid = $userServices->getSpreadUid($uid, $userInfo);
  882. $spread_two_uid = 0;
  883. if ($spread_one_uid > 0 && $one_user_info = $userServices->getUserInfo($spread_one_uid)) {
  884. $spread_two_uid = $userServices->getSpreadUid($spread_one_uid, $one_user_info, false);
  885. }
  886. //计算分销等级之后的佣金比例
  887. [$storeBrokerageRatio, $storeBrokerageTwo] = app()->make(AgentLevelServices::class)->getAgentLevelBrokerage($storeBrokerageRatio, $storeBrokerageTwo, $spread_one_uid, $spread_two_uid);
  888. //判断返佣层级为一级时,将二级用户uid和二级分佣比例改为0
  889. if (sys_config('brokerage_level') == 1) {
  890. $storeBrokerageTwo = $spread_two_uid = 0;
  891. }
  892. return [$storeBrokerageRatio, $storeBrokerageTwo, $spread_one_uid, $spread_two_uid];
  893. }
  894. }