StoreOrderServices.php 131 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917
  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\dao\order\StoreOrderDao;
  13. use app\jobs\AutoCommentJob;
  14. use app\services\activity\combination\StorePinkServices;
  15. use app\services\activity\seckill\StoreSeckillServices;
  16. use app\services\BaseServices;
  17. use app\services\other\PosterServices;
  18. use app\services\other\UploadService;
  19. use app\services\pay\OrderPayServices;
  20. use app\services\pay\PayServices;
  21. use app\services\product\product\StoreProductLogServices;
  22. use app\services\serve\ServeServices;
  23. use app\services\system\attachment\SystemAttachmentServices;
  24. use app\services\system\store\SystemStoreServices;
  25. use app\services\user\UserInvoiceServices;
  26. use app\services\user\UserRechargeServices;
  27. use app\services\user\UserServices;
  28. use app\services\product\product\StoreProductReplyServices;
  29. use app\services\user\UserAddressServices;
  30. use app\services\user\UserBillServices;
  31. use app\services\user\UserLevelServices;
  32. use app\services\wechat\WechatUserServices;
  33. use crmeb\exceptions\AdminException;
  34. use crmeb\exceptions\ApiException;
  35. use crmeb\exceptions\PayException;
  36. use crmeb\services\app\MiniProgramService;
  37. use crmeb\services\CacheService;
  38. use crmeb\services\easywechat\orderShipping\MiniOrderService;
  39. use crmeb\services\FormBuilder as Form;
  40. use crmeb\services\printer\Printer;
  41. use crmeb\services\SystemConfigService;
  42. use crmeb\utils\Arr;
  43. use Guzzle\Http\EntityBody;
  44. use think\facade\Log;
  45. /**
  46. * Class StoreOrderServices
  47. * @package app\services\order
  48. * @method getOrderIdsCount(array $ids) 获取订单id下没有删除的订单数量
  49. * @method StoreOrderDao getUserOrderDetail(string $key, int $uid, array $with) 获取订单详情
  50. * @method chartTimePrice($start, $stop) 获取当前时间到指定时间的支付金额 管理员
  51. * @method chartTimeNumber($start, $stop) 获取当前时间到指定时间的支付订单数 管理员
  52. * @method together(array $where, string $field, string $together = 'sum') 聚合查询
  53. * @method getBuyCount($uid, $type, $typeId) 获取用户已购买此活动商品的个数
  54. * @method getDistinctCount(array $where, $field, ?bool $search = true)
  55. * @method getTrendData($time, $type, $timeType, $str) 用户趋势
  56. * @method getRegion($time, $channelType) 地域统计
  57. * @method getProductTrend($time, $timeType, $field, $str) 商品趋势
  58. * @method getList(array $where, array $field, int $page = 0, int $limit = 0, array $with = [])
  59. */
  60. class StoreOrderServices extends BaseServices
  61. {
  62. /**
  63. * 发货类型
  64. * @var string[]
  65. */
  66. public $deliveryType = [
  67. 'send' => '商家配送',
  68. 'express' => '快递配送',
  69. 'fictitious' => '虚拟发货',
  70. 'delivery_part_split' => '拆分部分发货',
  71. 'delivery_split' => '拆分发货完成'
  72. ];
  73. /**
  74. * StoreOrderProductServices constructor.
  75. * @param StoreOrderDao $dao
  76. */
  77. public function __construct(StoreOrderDao $dao)
  78. {
  79. $this->dao = $dao;
  80. }
  81. /**
  82. * 获取列表
  83. * @param array $where
  84. * @param array $field
  85. * @param array $with
  86. * @return array
  87. * @throws \think\db\exception\DataNotFoundException
  88. * @throws \think\db\exception\DbException
  89. * @throws \think\db\exception\ModelNotFoundException
  90. */
  91. public function getOrderList(array $where, array $field = ['*'], array $with = [])
  92. {
  93. [$page, $limit] = $this->getPageValue();
  94. $data = $this->dao->getOrderList($where, $field, $page, $limit, $with);
  95. $count = $this->dao->count($where, false);
  96. $data = $this->tidyOrderList($data);
  97. foreach ($data as &$item) {
  98. $refund_num = array_sum(array_column($item['refund'], 'refund_num'));
  99. $cart_num = 0;
  100. $vipTruePrice = 0;
  101. foreach ($item['_info'] as $items) {
  102. $cart_num += $items['cart_info']['cart_num'];
  103. $vipTruePrice = bcadd((string)$vipTruePrice, (string)$items['cart_info']['vip_truePrice'], 2);
  104. }
  105. $item['total_price'] = bcadd($item['total_price'], $vipTruePrice, 2);
  106. $item['is_all_refund'] = $refund_num == $cart_num;
  107. $item['pay_price'] = (float)$item['pay_price'];
  108. }
  109. return compact('data', 'count');
  110. }
  111. /**
  112. * 前端订单列表
  113. * @param array $where
  114. * @param array|string[] $field
  115. * @param array $with
  116. * @return array
  117. * @throws \think\db\exception\DataNotFoundException
  118. * @throws \think\db\exception\DbException
  119. * @throws \think\db\exception\ModelNotFoundException
  120. */
  121. public function getOrderApiList(array $where, array $field = ['*'], array $with = [])
  122. {
  123. [$page, $limit] = $this->getPageValue();
  124. $data = $this->dao->getOrderList($where, $field, $page, $limit, $with);
  125. foreach ($data as &$item) {
  126. $item = $this->tidyOrder($item, true);
  127. foreach ($item['cartInfo'] ?: [] as $key => $product) {
  128. if ($item['_status']['_type'] == 3) {
  129. $item['cartInfo'][$key]['add_time'] = isset($product['add_time']) ? date('Y-m-d H:i', (int)$product['add_time']) : '时间错误';
  130. }
  131. $item['cartInfo'][$key]['productInfo']['price'] = $product['truePrice'] ?? 0;
  132. }
  133. if (count($item['refund'])) {
  134. $refund_num = array_sum(array_column($item['refund'], 'refund_num'));
  135. $cart_num = array_sum(array_column($item['cartInfo'], 'cart_num'));
  136. $item['is_all_refund'] = $refund_num == $cart_num ? true : false;
  137. } else {
  138. $item['is_all_refund'] = false;
  139. }
  140. }
  141. return $data;
  142. }
  143. /**
  144. * 获取订单数量
  145. * @param int $uid
  146. * @return array
  147. * @throws \ReflectionException
  148. */
  149. public function getOrderData(int $uid = 0)
  150. {
  151. $data['order_count'] = (string)$this->dao->count(['uid' => $uid, 'refund_status' => [0, 3], 'pid' => 0, 'is_del' => 0, 'is_system_del' => 0]);
  152. $data['sum_price'] = (string)$this->dao->sum([
  153. ['uid', '=', $uid],
  154. ['paid', '=', 1],
  155. ['refund_status', '=', 0],
  156. ['pid', '>=', 0]
  157. ], 'pay_price', false);
  158. $countWhere = ['is_del' => 0, 'is_system_del' => 0];
  159. if ($uid) {
  160. $countWhere['uid'] = $uid;
  161. }
  162. $data['unpaid_count'] = (string)$this->dao->count(['status' => 0] + $countWhere);
  163. $data['unshipped_count'] = (string)$this->dao->count(['status' => 1] + $countWhere + ['pid' => 0]);
  164. $data['received_count'] = (string)$this->dao->count(['status' => 2] + $countWhere + ['pid' => 0]);
  165. $data['evaluated_count'] = (string)$this->dao->count(['status' => 3] + $countWhere + ['pid' => 0]);
  166. $data['complete_count'] = (string)$this->dao->count(['status' => 4] + $countWhere + ['pid' => 0]);
  167. /** @var StoreOrderRefundServices $storeOrderRefundServices */
  168. $storeOrderRefundServices = app()->make(StoreOrderRefundServices::class);
  169. $refund_where = ['is_cancel' => 0];
  170. if ($uid) $refund_where['uid'] = $uid;
  171. $data['refunding_count'] = (string)$storeOrderRefundServices->count($refund_where + ['refund_type' => [1, 2, 4, 5]]);
  172. $data['no_refund_count'] = (string)$storeOrderRefundServices->count($refund_where + ['refund_type' => 3]);
  173. $data['refunded_count'] = (string)$storeOrderRefundServices->count($refund_where + ['refund_type' => 6]);
  174. $data['refund_count'] = bcadd(bcadd($data['refunding_count'], $data['refunded_count'], 0), $data['no_refund_count'], 0);
  175. $data['yue_pay_status'] = (int)sys_config('balance_func_status') && (int)sys_config('yue_pay_status') == 1 ? (int)1 : (int)2;//余额支付 1 开启 2 关闭
  176. $data['pc_order_count'] = $data['order_count'] + $data['refunding_count'] + $data['refunded_count'];
  177. $data['pay_weixin_open'] = sys_config('pay_weixin_open', '0') != '0';//微信支付 1 开启 0 关闭
  178. $data['ali_pay_status'] = sys_config('ali_pay_status', '0') != '0';//支付包支付 1 开启 0 关闭
  179. $data['friend_pay_status'] = (int)sys_config('friend_pay_status') ?? 0;//好友代付 1 开启 0 关闭
  180. return $data;
  181. }
  182. /**
  183. * 订单详情数据格式化
  184. * @param $order
  185. * @param bool $detail 是否需要订单商品详情
  186. * @param bool $isPic 是否需要订单状态图片
  187. * @return mixed
  188. */
  189. public function tidyOrder($order, bool $detail = false, $isPic = false)
  190. {
  191. if ($detail == true && isset($order['id'])) {
  192. /** @var StoreOrderCartInfoServices $cartServices */
  193. $cartServices = app()->make(StoreOrderCartInfoServices::class);
  194. $cartInfos = $cartServices->getCartColunm(['oid' => $order['id']], 'cart_num,surplus_num,cart_info,refund_num', 'unique');
  195. $info = [];
  196. /** @var StoreProductReplyServices $replyServices */
  197. $replyServices = app()->make(StoreProductReplyServices::class);
  198. foreach ($cartInfos as $k => $cartInfo) {
  199. $cart = json_decode($cartInfo['cart_info'], true);
  200. $cart['cart_num'] = $cartInfo['cart_num'];
  201. $cart['surplus_num'] = $cartInfo['surplus_num'];
  202. $cart['refund_num'] = $cartInfo['refund_num'];
  203. $cart['surplus_refund_num'] = $cartInfo['surplus_num'] - $cartInfo['refund_num'];
  204. $cart['unique'] = $k;
  205. //新增是否评价字段
  206. $cart['is_reply'] = $replyServices->count(['unique' => $k]);
  207. if (isset($cart['productInfo']['attrInfo'])) {
  208. $cart['productInfo']['attrInfo'] = get_thumb_water($cart['productInfo']['attrInfo']);
  209. }
  210. $cart['productInfo'] = get_thumb_water($cart['productInfo']);
  211. //一种商品买多件 计算总优惠
  212. $cart['vip_sum_truePrice'] = bcmul($cart['vip_truePrice'], $cart['cart_num'] ? $cart['cart_num'] : 1, 2);
  213. $cart['is_valid'] = 1;
  214. array_push($info, $cart);
  215. unset($cart);
  216. }
  217. $order['cartInfo'] = $info;
  218. }
  219. /** @var StoreOrderStatusServices $statusServices */
  220. $statusServices = app()->make(StoreOrderStatusServices::class);
  221. $status = [];
  222. if (!$order['paid'] && $order['pay_type'] == 'offline' && !$order['status'] >= 2) {
  223. $status['_type'] = 9;
  224. $status['_title'] = '线下付款,未支付';
  225. $status['_msg'] = '等待商家处理,请耐心等待';
  226. $status['_class'] = 'nobuy';
  227. } else if (!$order['paid']) {
  228. $status['_type'] = 0;
  229. $status['_title'] = '未支付';
  230. //系统预设取消订单时间段
  231. $keyValue = ['order_cancel_time', 'order_activity_time', 'order_bargain_time', 'order_seckill_time', 'order_pink_time'];
  232. //获取配置
  233. $systemValue = SystemConfigService::more($keyValue);
  234. //格式化数据
  235. $systemValue = Arr::setValeTime($keyValue, is_array($systemValue) ? $systemValue : []);
  236. if ($order['pink_id'] || $order['combination_id']) {
  237. $order_pink_time = $systemValue['order_pink_time'] ?: $systemValue['order_activity_time'];
  238. $time = $order['add_time'] + $order_pink_time * 3600;
  239. $status['_msg'] = '请在' . date('m-d H:i:s', $time) . '前完成支付!';
  240. } else if ($order['seckill_id']) {
  241. $order_seckill_time = $systemValue['order_seckill_time'] ?: $systemValue['order_activity_time'];
  242. $time = $order['add_time'] + $order_seckill_time * 3600;
  243. $status['_msg'] = '请在' . date('m-d H:i:s', $time) . '前完成支付!';
  244. } else if ($order['bargain_id']) {
  245. $order_bargain_time = $systemValue['order_bargain_time'] ?: $systemValue['order_activity_time'];
  246. $time = $order['add_time'] + $order_bargain_time * 3600;
  247. $status['_msg'] = '请在' . date('m-d H:i:s', $time) . '前完成支付!';
  248. } else {
  249. $time = $order['add_time'] + $systemValue['order_cancel_time'] * 3600;
  250. $status['_msg'] = '请在' . date('m-d H:i:s', (int)$time) . '前完成支付!';
  251. }
  252. $status['_class'] = 'nobuy';
  253. } else if ($order['status'] == 4) {
  254. if ($order['delivery_type'] == 'send') {//TODO 送货
  255. $status['_type'] = 1;
  256. $status['_title'] = '待收货';
  257. $status['_msg'] = date('m月d日H时i分', $statusServices->value(['oid' => $order['id'], 'change_type' => 'delivery'], 'change_time')) . '服务商已送货';
  258. $status['_class'] = 'state-ysh';
  259. } elseif ($order['delivery_type'] == 'express') {//TODO 发货
  260. $status['_type'] = 1;
  261. $status['_title'] = '待收货';
  262. $status['_msg'] = date('m月d日H时i分', $statusServices->value(['oid' => $order['id'], 'change_type' => 'delivery_goods'], 'change_time')) . '服务商已发货';
  263. $status['_class'] = 'state-ysh';
  264. } elseif ($order['delivery_type'] == 'split') {//拆分发货
  265. $status['_type'] = 1;
  266. $status['_title'] = '待收货';
  267. $status['_msg'] = date('m月d日H时i分', $statusServices->value(['oid' => $order['id'], 'change_type' => 'delivery_part_split'], 'change_time')) . '服务商已拆分多个包裹发货';
  268. $status['_class'] = 'state-ysh';
  269. } else {
  270. $status['_type'] = 1;
  271. $status['_title'] = '待收货';
  272. $status['_msg'] = date('m月d日H时i分', $statusServices->value(['oid' => $order['id'], 'change_type' => 'delivery_fictitious'], 'change_time')) . '服务商已虚拟发货';
  273. $status['_class'] = 'state-ysh';
  274. }
  275. } else if ($order['refund_status'] == 1) {
  276. if (in_array($order['refund_type'], [0, 1, 2])) {
  277. $status['_type'] = -1;
  278. $status['_title'] = '申请退款中';
  279. $status['_msg'] = '商家审核中,请耐心等待';
  280. $status['_class'] = 'state-sqtk';
  281. } elseif ($order['refund_type'] == 4) {
  282. $status['_type'] = -1;
  283. $status['_title'] = '申请退款中';
  284. $status['_msg'] = '商家同意退款,请填写退货订单号';
  285. $status['_class'] = 'state-sqtk';
  286. $status['refund_name'] = sys_config('refund_name', '');
  287. $status['refund_phone'] = sys_config('refund_phone', '');
  288. $status['refund_address'] = sys_config('refund_address', '');
  289. } elseif ($order['refund_type'] == 5) {
  290. $status['_type'] = -1;
  291. $status['_title'] = '申请退款中';
  292. $status['_msg'] = '等待商家收货';
  293. $status['_class'] = 'state-sqtk';
  294. $status['refund_name'] = sys_config('refund_name', '');
  295. $status['refund_phone'] = sys_config('refund_phone', '');
  296. $status['refund_address'] = sys_config('refund_address', '');
  297. }
  298. } else if ($order['refund_status'] == 2 || $order['refund_type'] == 6) {
  299. $status['_type'] = -2;
  300. $status['_title'] = '已退款';
  301. $status['_msg'] = '已为您退款,感谢您的支持';
  302. $status['_class'] = 'state-sqtk';
  303. } else if ($order['refund_status'] == 3) {
  304. $status['_type'] = -1;
  305. $status['_title'] = '部分退款(子订单)';
  306. $status['_msg'] = '拆分发货,部分退款';
  307. $status['_class'] = 'state-sqtk';
  308. } else if ($order['refund_status'] == 4) {
  309. $status['_type'] = -1;
  310. $status['_title'] = '子订单已全部申请退款中';
  311. $status['_msg'] = '拆分发货,全部退款';
  312. $status['_class'] = 'state-sqtk';
  313. } else if (!$order['status']) {
  314. if ($order['pink_id']) {
  315. /** @var StorePinkServices $pinkServices */
  316. $pinkServices = app()->make(StorePinkServices::class);
  317. if ($pinkServices->getCount(['id' => $order['pink_id'], 'status' => 1])) {
  318. $status['_type'] = 1;
  319. $status['_title'] = '拼团中';
  320. $status['_msg'] = '等待其他人参加拼团';
  321. $status['_class'] = 'state-nfh';
  322. } else {
  323. $status['_type'] = 1;
  324. $status['_title'] = '未发货';
  325. $status['_msg'] = '商家未发货,请耐心等待';
  326. $status['_class'] = 'state-nfh';
  327. }
  328. } else {
  329. if ($order['shipping_type'] === 1) {
  330. $status['_type'] = 1;
  331. $status['_title'] = '未发货';
  332. if ($order['advance_id']) {
  333. $status['_msg'] = date('Y-m-d', $order['cartInfo'][0]['productInfo']['presale_end_time']) . '预售结束后' . $order['cartInfo'][0]['productInfo']['presale_day'] . '天内发货,请耐心等待';
  334. } else {
  335. $status['_msg'] = '商家未发货,请耐心等待';
  336. }
  337. $status['_class'] = 'state-nfh';
  338. } else {
  339. $status['_type'] = 1;
  340. $status['_title'] = '待核销';
  341. $status['_msg'] = '待核销,请到核销点进行核销';
  342. $status['_class'] = 'state-nfh';
  343. }
  344. }
  345. } else if ($order['status'] == 1) {
  346. if ($order['delivery_type'] == 'send') {//TODO 送货
  347. $status['_type'] = 2;
  348. $status['_title'] = '待收货';
  349. $status['_msg'] = date('m月d日H时i分', $statusServices->value(['oid' => $order['id'], 'change_type' => 'delivery'], 'change_time')) . '服务商已送货';
  350. $status['_class'] = 'state-ysh';
  351. } elseif ($order['delivery_type'] == 'express') {//TODO 发货
  352. $status['_type'] = 2;
  353. $status['_title'] = '待收货';
  354. $status['_msg'] = date('m月d日H时i分', $statusServices->value(['oid' => $order['id'], 'change_type' => 'delivery_goods'], 'change_time')) . '服务商已发货';
  355. $status['_class'] = 'state-ysh';
  356. } elseif ($order['delivery_type'] == 'split') {//拆分发货
  357. $status['_type'] = 2;
  358. $status['_title'] = '待收货';
  359. $status['_msg'] = date('m月d日H时i分', $statusServices->value(['oid' => $order['id'], 'change_type' => 'delivery_split'], 'change_time')) . '服务商已拆分多个包裹发货';
  360. $status['_class'] = 'state-ysh';
  361. } else {
  362. $status['_type'] = 2;
  363. $status['_title'] = '待收货';
  364. $status['_msg'] = date('m月d日H时i分', $statusServices->value(['oid' => $order['id'], 'change_type' => 'delivery_fictitious'], 'change_time')) . '服务商已虚拟发货';
  365. $status['_class'] = 'state-ysh';
  366. }
  367. } else if ($order['status'] == 2) {
  368. $status['_type'] = 3;
  369. $status['_title'] = '待评价';
  370. $status['_msg'] = '已收货,快去评价一下吧';
  371. $status['_class'] = 'state-ypj';
  372. } else if ($order['status'] == 3) {
  373. $status['_type'] = 4;
  374. $status['_title'] = '交易完成';
  375. $status['_msg'] = '交易完成,感谢您的支持';
  376. $status['_class'] = 'state-ytk';
  377. }
  378. if (isset($order['pay_type']))
  379. $status['_payType'] = $status['_type'] == 0 ? '' : PayServices::PAY_TYPE[$order['pay_type']] ?? '其他方式';
  380. if (isset($order['delivery_type']))
  381. $status['_deliveryType'] = $this->deliveryType[$order['delivery_type']] ?? '其他方式';
  382. $order['_status'] = $status;
  383. $order['_pay_time'] = isset($order['pay_time']) && $order['pay_time'] != null ? date('Y-m-d H:i:s', $order['pay_time']) : '';
  384. $order['_add_time'] = isset($order['add_time']) ? (strstr((string)$order['add_time'], '-') === false ? date('Y-m-d H:i:s', $order['add_time']) : $order['add_time']) : '';
  385. //系统预设取消订单时间段
  386. $keyValue = ['order_cancel_time', 'order_activity_time', 'order_bargain_time', 'order_seckill_time', 'order_pink_time'];
  387. //获取配置
  388. $systemValue = SystemConfigService::more($keyValue);
  389. //格式化数据
  390. $systemValue = Arr::setValeTime($keyValue, is_array($systemValue) ? $systemValue : []);
  391. if ($order['seckill_id']) {
  392. $secs = $systemValue['order_seckill_time'] ? $systemValue['order_seckill_time'] : $systemValue['order_activity_time'];
  393. } elseif ($order['bargain_id']) {
  394. $secs = $systemValue['order_bargain_time'] ? $systemValue['order_bargain_time'] : $systemValue['order_activity_time'];
  395. } elseif ($order['combination_id']) {
  396. $secs = $systemValue['order_pink_time'] ? $systemValue['order_pink_time'] : $systemValue['order_activity_time'];
  397. } else {
  398. $secs = $systemValue['order_cancel_time'];
  399. }
  400. $order['stop_time'] = $secs * 3600 + $order['add_time'];
  401. $order['status_pic'] = '';
  402. //获取商品状态图片
  403. if ($isPic) {
  404. $order_details_images = sys_data('order_details_images') ?: [];
  405. foreach ($order_details_images as $image) {
  406. if (isset($image['order_status']) && $image['order_status'] == $order['_status']['_type']) {
  407. $order['status_pic'] = $image['pic'];
  408. break;
  409. }
  410. }
  411. }
  412. if ($order['seckill_id'] || $order['bargain_id'] || $order['combination_id'] || $order['advance_id']) {
  413. if ($order['seckill_id']) $order['type'] = 1;
  414. if ($order['bargain_id']) $order['type'] = 2;
  415. if ($order['combination_id']) $order['type'] = 3;
  416. if ($order['advance_id']) $order['type'] = 4;
  417. }
  418. $order['offlinePayStatus'] = (int)sys_config('offline_pay_status') ?? (int)2;
  419. $log = $statusServices->getColumn(['oid' => $order['id']], 'change_time', 'change_type');
  420. if (isset($log['delivery'])) {
  421. $delivery = date('Y-m-d', $log['delivery']);
  422. } elseif (isset($log['delivery_goods'])) {
  423. $delivery = date('Y-m-d', $log['delivery_goods']);
  424. } elseif (isset($log['delivery_fictitious'])) {
  425. $delivery = date('Y-m-d', $log['delivery_fictitious']);
  426. } else {
  427. $delivery = '';
  428. }
  429. $order['order_log'] = [
  430. 'create' => isset($log['cache_key_create_order']) ? date('Y-m-d', $log['cache_key_create_order']) : '',
  431. 'pay' => isset($log['pay_success']) ? date('Y-m-d', $log['pay_success']) : '',
  432. 'delivery' => $delivery,
  433. 'take' => isset($log['take_delivery']) ? date('Y-m-d', $log['take_delivery']) : '',
  434. 'complete' => isset($log['check_order_over']) ? date('Y-m-d', $log['check_order_over']) : '',
  435. ];
  436. return $order;
  437. }
  438. /**
  439. * 数据转换
  440. * @param array $data
  441. * @return array
  442. */
  443. public function tidyOrderList(array $data)
  444. {
  445. /** @var StoreOrderCartInfoServices $services */
  446. $services = app()->make(StoreOrderCartInfoServices::class);
  447. foreach ($data as &$item) {
  448. $item['_info'] = $services->getOrderCartInfo((int)$item['id']);
  449. $item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
  450. $item['_refund_time'] = isset($item['refund_reason_time']) && $item['refund_reason_time'] ? date('Y-m-d H:i:s', $item['refund_reason_time']) : '';
  451. $item['_pay_time'] = isset($item['pay_time']) && $item['pay_time'] ? date('Y-m-d H:i:s', $item['pay_time']) : '';
  452. if (($item['pink_id'] || $item['combination_id']) && isset($item['pinkStatus'])) {
  453. switch ($item['pinkStatus']) {
  454. case 1:
  455. $item['pink_name'] = '[拼团订单]正在进行中';
  456. $item['color'] = '#f00';
  457. break;
  458. case 2:
  459. $item['pink_name'] = '[拼团订单]已完成';
  460. $item['color'] = '#00f';
  461. break;
  462. case 3:
  463. $item['pink_name'] = '[拼团订单]未完成';
  464. $item['color'] = '#f0f';
  465. break;
  466. default:
  467. $item['pink_name'] = '[拼团订单]历史订单';
  468. $item['color'] = '#FF7D00';
  469. break;
  470. }
  471. } elseif ($item['combination_id']) {
  472. $item['pink_name'] = '[拼团订单]';
  473. $item['color'] = '#FF7D00';
  474. } elseif ($item['seckill_id']) {
  475. $item['pink_name'] = '[秒杀订单]';
  476. $item['color'] = '#3491FA';
  477. } elseif ($item['bargain_id']) {
  478. $item['pink_name'] = '[砍价订单]';
  479. $item['color'] = '#F7BA1E';
  480. } elseif ($item['advance_id']) {
  481. $item['pink_name'] = '[预售订单]';
  482. $item['color'] = '#B27FEB';
  483. } else {
  484. if ($item['shipping_type'] == 1) {
  485. $item['pink_name'] = '[普通订单]';
  486. $item['color'] = '#333';
  487. } else if ($item['shipping_type'] == 2) {
  488. $item['pink_name'] = '[核销订单]';
  489. $item['color'] = '#8956E8';
  490. }
  491. }
  492. if ($item['paid'] == 1) {
  493. switch ($item['pay_type']) {
  494. case PayServices::WEIXIN_PAY:
  495. $item['pay_type_name'] = '微信支付';
  496. break;
  497. case PayServices::YUE_PAY:
  498. $item['pay_type_name'] = '余额支付';
  499. break;
  500. case PayServices::OFFLINE_PAY:
  501. $item['pay_type_name'] = '线下支付';
  502. break;
  503. case PayServices::ALIAPY_PAY:
  504. $item['pay_type_name'] = '支付宝支付';
  505. break;
  506. case PayServices::ALLIN_PAY:
  507. $item['pay_type_name'] = '通联支付';
  508. break;
  509. default:
  510. $item['pay_type_name'] = '其他支付';
  511. break;
  512. }
  513. } else {
  514. switch ($item['pay_type']) {
  515. case 'offline':
  516. $item['pay_type_name'] = '线下支付';
  517. $item['pay_type_info'] = 1;
  518. break;
  519. default:
  520. $item['pay_type_name'] = '';
  521. break;
  522. }
  523. }
  524. $status_name = ['status_name' => '', 'pics' => []];
  525. if ($item['paid'] == 0 && $item['status'] == 0) {
  526. $status_name['status_name'] = '未支付';
  527. } else if ($item['paid'] == 1 && $item['status'] == 0 && $item['shipping_type'] == 1 && $item['refund_status'] == 0) {
  528. $status_name['status_name'] = $item['combination_id'] && isset($item['pinkStatus']) && $item['pinkStatus'] == 1 ? '未发货(拼团中)' : '未发货';
  529. } else if ($item['paid'] == 1 && $item['status'] == 4 && $item['shipping_type'] == 1 && $item['refund_status'] == 0) {
  530. $status_name['status_name'] = '部分发货';
  531. } else if ($item['paid'] == 1 && $item['status'] == 0 && $item['shipping_type'] == 2 && $item['refund_status'] == 0) {
  532. $status_name['status_name'] = '未核销';
  533. } else if ($item['paid'] == 1 && $item['status'] == 1 && $item['shipping_type'] == 1 && $item['refund_status'] == 0) {
  534. $status_name['status_name'] = '待收货';
  535. } else if ($item['paid'] == 1 && $item['status'] == 1 && $item['shipping_type'] == 2 && $item['refund_status'] == 0) {
  536. $status_name['status_name'] = '未核销';
  537. } else if ($item['paid'] == 1 && $item['status'] == 2 && $item['refund_status'] == 0) {
  538. $status_name['status_name'] = '待评价';
  539. } else if ($item['paid'] == 1 && $item['status'] == 3 && $item['refund_status'] == 0) {
  540. $status_name['status_name'] = '已完成';
  541. } else if ($item['paid'] == 1 && $item['refund_status'] == 1) {
  542. $refundReasonTime = date('Y-m-d H:i', $item['refund_reason_time']);
  543. $refundReasonWapImg = json_decode($item['refund_reason_wap_img'], true);
  544. $refundReasonWapImg = $refundReasonWapImg ?: [];
  545. $img = [];
  546. if (count($refundReasonWapImg)) {
  547. foreach ($refundReasonWapImg as $itemImg) {
  548. if (strlen(trim($itemImg)))
  549. $img[] = $itemImg;
  550. }
  551. }
  552. $status_name['status_name'] = '退款中';
  553. $status_name['pics'] = $img;
  554. } else if ($item['paid'] == 1 && $item['refund_status'] == 2) {
  555. $status_name['status_name'] = '已退款';
  556. } else if ($item['paid'] == 1 && $item['refund_status'] == 3) {
  557. $status_name['status_name'] = <<<HTML
  558. <b style="color:#f124c7">部分退款</b><br/>
  559. HTML;
  560. } else if ($item['paid'] == 1 && $item['refund_status'] == 4) {
  561. $status_name['status_name'] = <<<HTML
  562. <b style="color:#f124c7">退款中</b><br/>
  563. HTML;
  564. }
  565. $item['status_name'] = $status_name;
  566. if ($item['paid'] == 0 && $item['status'] == 0 && $item['refund_status'] == 0) {
  567. $item['_status'] = 1;//未支付
  568. } else if ($item['paid'] == 1 && $item['status'] == 0 && $item['refund_status'] == 0) {
  569. $item['_status'] = 2;//已支付 未发货
  570. } else if ($item['paid'] == 1 && $item['status'] == 4 && $item['refund_status'] == 0) {
  571. $item['_status'] = 8;//已支付 部分发货
  572. } else if ($item['paid'] == 1 && $item['refund_status'] == 1) {
  573. $item['_status'] = 3;//已支付 申请退款中
  574. } else if ($item['paid'] == 1 && $item['status'] == 1 && $item['refund_status'] == 0) {
  575. $item['_status'] = 4;//已支付 待收货
  576. } else if ($item['paid'] == 1 && $item['status'] == 2 && $item['refund_status'] == 0) {
  577. $item['_status'] = 5;//已支付 待评价
  578. } else if ($item['paid'] == 1 && $item['status'] == 3 && $item['refund_status'] == 0) {
  579. $item['_status'] = 6;//已支付 已完成
  580. } else if ($item['paid'] == 1 && $item['refund_status'] == 2) {
  581. $item['_status'] = 7;//已支付 已退款
  582. } else if ($item['paid'] == 1 && $item['refund_status'] == 3 && $item['status'] == 4) {
  583. $item['_status'] = 9;//拆单发货 部分申请退款
  584. } else if ($item['paid'] == 1 && $item['refund_status'] == 4) {
  585. $item['_status'] = 10;//拆单发货 已全部申请退款
  586. } else if ($item['paid'] == 1 && $item['refund_status'] == 3 && $item['status'] == 0) {
  587. $item['_status'] = 11;//拆单退款 未发货
  588. }
  589. if ($item['clerk_id'] == 0 && !isset($item['clerk_name'])) {
  590. $item['clerk_name'] = '总平台';
  591. }
  592. //根据核销员更改store_name
  593. if ($item['clerk_id'] && isset($item['staff_store_id']) && $item['staff_store_id']) {
  594. /** @var SystemStoreServices $store */
  595. $store = app()->make(SystemStoreServices::class);
  596. $storeOne = $store->value(['id' => $item['staff_store_id']], 'name');
  597. if ($storeOne) $item['store_name'] = $storeOne;
  598. }
  599. }
  600. return $data;
  601. }
  602. /**
  603. * 处理订单金额
  604. * @param $where
  605. * @return array
  606. */
  607. public function getOrderPrice($where)
  608. {
  609. if (isset($where['refund_type']) && $where['refund_type']) unset($where['refund_type']);
  610. $where['is_del'] = 0;//删除订单不统计
  611. $price['today_pay_price'] = 0;//今日支付金额
  612. $price['pay_price'] = 0;//支付金额
  613. $price['refund_price'] = 0;//退款金额
  614. $price['pay_price_wx'] = 0;//微信支付金额
  615. $price['pay_price_yue'] = 0;//余额支付金额
  616. $price['pay_price_offline'] = 0;//线下支付金额
  617. $price['pay_price_other'] = 0;//其他支付金额
  618. $price['use_integral'] = 0;//用户使用积分
  619. $price['back_integral'] = 0;//退积分总数
  620. $price['deduction_price'] = 0;//抵扣金额
  621. $price['total_num'] = 0; //商品总数
  622. $price['today_count_sum'] = 0; //今日订单总数
  623. $price['count_sum'] = 0; //订单总数
  624. $price['brokerage'] = 0;
  625. $price['pay_postage'] = 0;
  626. $whereData = ['is_del' => 0];
  627. if ($where['status'] == '' && $where['pay_type'] != 3) {
  628. $whereData['paid'] = 1;
  629. }
  630. $ids = $this->dao->column($where + $whereData, 'id');
  631. if (count($ids)) {
  632. /** @var UserBillServices $services */
  633. $services = app()->make(UserBillServices::class);
  634. $price['brokerage'] = $services->getBrokerageNumSum($ids);
  635. }
  636. $price['refund_price'] = $this->dao->together($where + ['is_del' => 0, 'paid' => 1, 'refund_status' => 2], 'refund_price');
  637. $sumNumber = $this->dao->search($where + $whereData)->field([
  638. 'sum(total_num) as sum_total_num',
  639. 'count(id) as count_sum',
  640. 'sum(pay_price) as sum_pay_price',
  641. 'sum(pay_postage) as sum_pay_postage',
  642. 'sum(use_integral) as sum_use_integral',
  643. 'sum(back_integral) as sum_back_integral',
  644. 'sum(deduction_price) as sum_deduction_price'
  645. ])->find();
  646. if ($sumNumber) {
  647. $price['count_sum'] = $sumNumber['count_sum'];
  648. $price['total_num'] = $sumNumber['sum_total_num'];
  649. $price['pay_price'] = $sumNumber['sum_pay_price'];
  650. $price['pay_postage'] = $sumNumber['sum_pay_postage'];
  651. $price['use_integral'] = $sumNumber['sum_use_integral'];
  652. $price['back_integral'] = $sumNumber['sum_back_integral'];
  653. $price['deduction_price'] = $sumNumber['sum_deduction_price'];
  654. }
  655. $list = $this->dao->column($where + $whereData, 'sum(pay_price) as sum_pay_price,pay_type', 'id', 'pay_type');
  656. foreach ($list as $v) {
  657. if ($v['pay_type'] == 'weixin') {
  658. $price['pay_price_wx'] = $v['sum_pay_price'];
  659. } elseif ($v['pay_type'] == 'yue') {
  660. $price['pay_price_yue'] = $v['sum_pay_price'];
  661. } elseif ($v['pay_type'] == 'offline') {
  662. $price['pay_price_offline'] = $v['sum_pay_price'];
  663. } else {
  664. $price['pay_price_other'] = $v['sum_pay_price'];
  665. }
  666. }
  667. $where['time'] = 'today';
  668. $sumNumber = $this->dao->search($where + $whereData)->field([
  669. 'count(id) as today_count_sum',
  670. 'sum(pay_price) as today_pay_price',
  671. ])->find();
  672. if ($sumNumber) {
  673. $price['today_count_sum'] = $sumNumber['today_count_sum'];
  674. $price['today_pay_price'] = $where['status'] !== 0 ? $sumNumber['today_pay_price'] : 0;
  675. }
  676. return $price;
  677. }
  678. /**
  679. * 获取订单列表页面统计数据
  680. * @param $where
  681. * @return array
  682. */
  683. public function getBadge($where)
  684. {
  685. $price = $this->getOrderPrice($where);
  686. return [
  687. [
  688. 'name' => '订单数量',
  689. 'field' => '件',
  690. 'count' => $price['count_sum'],
  691. 'className' => 'md-basket',
  692. 'col' => 6
  693. ],
  694. [
  695. 'name' => '订单金额',
  696. 'field' => '元',
  697. 'count' => $price['pay_price'],
  698. 'className' => 'md-pricetags',
  699. 'col' => 6
  700. ],
  701. [
  702. 'name' => '今日订单数量',
  703. 'field' => '件',
  704. 'count' => $price['today_count_sum'],
  705. 'className' => 'ios-chatbubbles',
  706. 'col' => 6
  707. ],
  708. [
  709. 'name' => '今日支付金额',
  710. 'field' => '元',
  711. 'count' => $price['today_pay_price'],
  712. 'className' => 'ios-cash',
  713. 'col' => 6
  714. ],
  715. ];
  716. }
  717. /**
  718. *
  719. * @param array $where
  720. * @return mixed
  721. */
  722. /**
  723. * @param array $where
  724. * @return array
  725. * @throws \ReflectionException
  726. * @author wuhaotian
  727. * @email 442384644@qq.com
  728. * @date 2024/3/14
  729. */
  730. public function orderCount(array $where)
  731. {
  732. $where['is_system_del'] = 0;
  733. $where['pid'] = 0;
  734. $data['un_paid'] = $this->dao->count($where + ['status' => 0], false);
  735. $data['un_send'] = $this->dao->count($where + ['status' => 1], false);
  736. return $data;
  737. }
  738. /**
  739. * 创建修改订单表单
  740. * @param int $id
  741. * @return array
  742. * @throws \FormBuilder\Exception\FormBuilderException
  743. */
  744. public function updateForm(int $id)
  745. {
  746. $product = $this->dao->get($id);
  747. if (!$product) {
  748. throw new AdminException(100026);
  749. }
  750. $f = [];
  751. $f[] = Form::input('order_id', '订单编号', $product->getData('order_id'))->disabled(true);
  752. $f[] = Form::hidden('total_price', (float)$product->getData('total_price'));
  753. $f[] = Form::hidden('pay_postage', (float)$product->getData('pay_postage') ?: 0);
  754. $f[] = Form::number('pay_price', '实际支付金额', (float)$product->getData('pay_price'))->min(0);
  755. $f[] = Form::number('gain_integral', '赠送积分', (float)$product->getData('gain_integral') ?: 0)->min(0);
  756. return create_form('修改订单', $f, $this->url('/order/update/' . $id), 'PUT');
  757. }
  758. /**
  759. * 修改订单
  760. * @param int $id
  761. * @param array $data
  762. * @return mixed
  763. * @throws \Exception
  764. */
  765. public function updateOrder(int $id, array $data)
  766. {
  767. $order = $this->dao->getOne(['id' => $id, 'is_del' => 0]);
  768. if (!$order) {
  769. throw new AdminException(400118);
  770. }
  771. /** @var StoreOrderCreateServices $createServices */
  772. $createServices = app()->make(StoreOrderCreateServices::class);
  773. $data['order_id'] = $createServices->getNewOrderId('cp');
  774. if (sys_config('user_brokerage_type') == 1) {
  775. $percent = $order['pay_price'] != 0 ? bcdiv((string)$data['pay_price'], (string)$order['pay_price'], 6) : $order['pay_price'];
  776. if ($order['one_brokerage'] > 0) {
  777. $data['one_brokerage'] = bcmul((string)$order['one_brokerage'], $percent, 2);
  778. }
  779. if ($order['two_brokerage'] > 0) {
  780. $data['two_brokerage'] = bcmul((string)$order['two_brokerage'], $percent, 2);
  781. }
  782. if ($order['staff_brokerage'] > 0) {
  783. $data['staff_brokerage'] = bcmul((string)$order['staff_brokerage'], $percent, 2);
  784. }
  785. if ($order['agent_brokerage'] > 0) {
  786. $data['agent_brokerage'] = bcmul((string)$order['agent_brokerage'], $percent, 2);
  787. }
  788. if ($order['division_brokerage'] > 0) {
  789. $data['division_brokerage'] = bcmul((string)$order['division_brokerage'], $percent, 2);
  790. }
  791. }
  792. /** @var StoreOrderStatusServices $services */
  793. $services = app()->make(StoreOrderStatusServices::class);
  794. return $this->transaction(function () use ($id, $data, $services) {
  795. $res = $this->dao->update($id, $data);
  796. $res = $res && $services->save([
  797. 'oid' => $id,
  798. 'change_type' => 'order_edit',
  799. 'change_time' => time(),
  800. 'change_message' => '修改商品总价为:' . $data['total_price'] . ' 实际支付金额' . $data['pay_price']
  801. ]);
  802. if (isset($data['gain_integral'])) {
  803. $res = $res && $services->save([
  804. 'oid' => $id,
  805. 'change_type' => 'order_edit',
  806. 'change_time' => time(),
  807. 'change_message' => '修改订单赠送积分为:' . $data['gain_integral']
  808. ]);
  809. }
  810. if ($res) {
  811. $order = $this->dao->getOne(['id' => $id, 'is_del' => 0]);
  812. //改价短信提醒
  813. event('NoticeListener', [['order' => $order, 'pay_price' => $data['pay_price']], 'price_revision']);
  814. //自定义消息-订单改价
  815. $order['change_price'] = $data['pay_price'];
  816. event('NoticeListener', [$order['uid'], $order, 'price_change_price']);
  817. //自定义事件-订单改价
  818. event('CustomEventListener', ['admin_order_change', [
  819. 'uid' => $order['uid'],
  820. 'order_id' => $data['order_id'],
  821. 'pay_price' => $data['pay_price'],
  822. 'gain_integral' => $data['gain_integral'],
  823. 'change_time' => date('Y-m-d H:i:s'),
  824. ]]);
  825. return $data['order_id'];
  826. } else {
  827. throw new AdminException(100007);
  828. }
  829. });
  830. }
  831. /**
  832. * 订单图表
  833. * @param $cycle
  834. * @return array
  835. */
  836. public function orderCharts($cycle)
  837. {
  838. $datalist = [];
  839. switch ($cycle) {
  840. case 'thirtyday':
  841. $datebefor = date('Y-m-d', strtotime('-30 day'));
  842. $dateafter = date('Y-m-d 23:59:59');
  843. //上期
  844. $pre_datebefor = date('Y-m-d', strtotime('-60 day'));
  845. $pre_dateafter = date('Y-m-d', strtotime('-30 day'));
  846. for ($i = -29; $i <= 0; $i++) {
  847. $datalist[date('m-d', strtotime($i . ' day'))] = date('m-d', strtotime($i . ' day'));
  848. }
  849. $order_list = $this->dao->orderAddTimeList($datebefor, $dateafter, '30');
  850. if (empty($order_list)) return ['yAxis' => [], 'legend' => [], 'xAxis' => [], 'serise' => [], 'pre_cycle' => [], 'cycle' => []];
  851. foreach ($order_list as $k => &$v) {
  852. $order_list[$v['day']] = $v;
  853. }
  854. $cycle_list = [];
  855. foreach ($datalist as $dk => $dd) {
  856. if (!empty($order_list[$dd])) {
  857. $cycle_list[$dd] = $order_list[$dd];
  858. } else {
  859. $cycle_list[$dd] = ['count' => 0, 'day' => $dd, 'price' => ''];
  860. }
  861. }
  862. $chartdata = [];
  863. $data = [];//临时
  864. $chartdata['yAxis']['maxnum'] = 0;//最大值数量
  865. $chartdata['yAxis']['maxprice'] = 0;//最大值金额
  866. foreach ($cycle_list as $k => $v) {
  867. $data['day'][] = $v['day'];
  868. $data['count'][] = $v['count'];
  869. $data['price'][] = round($v['price'], 2);
  870. if ($chartdata['yAxis']['maxnum'] < $v['count'])
  871. $chartdata['yAxis']['maxnum'] = $v['count'];//日最大订单数
  872. if ($chartdata['yAxis']['maxprice'] < $v['price'])
  873. $chartdata['yAxis']['maxprice'] = $v['price'];//日最大金额
  874. }
  875. $chartdata['legend'] = ['订单金额', '订单数'];//分类
  876. $chartdata['xAxis'] = $data['day'];//X轴值
  877. $series1 = ['normal' => ['color' => [
  878. 'x' => 0, 'y' => 0, 'x2' => 0, 'y2' => 1,
  879. 'colorStops' => [
  880. [
  881. 'offset' => 0,
  882. 'color' => '#69cdff'
  883. ],
  884. [
  885. 'offset' => 0.5,
  886. 'color' => '#3eb3f7'
  887. ],
  888. [
  889. 'offset' => 1,
  890. 'color' => '#1495eb'
  891. ]
  892. ]
  893. ]]
  894. ];
  895. $series2 = ['normal' => ['color' => [
  896. 'x' => 0, 'y' => 0, 'x2' => 0, 'y2' => 1,
  897. 'colorStops' => [
  898. [
  899. 'offset' => 0,
  900. 'color' => '#6fdeab'
  901. ],
  902. [
  903. 'offset' => 0.5,
  904. 'color' => '#44d693'
  905. ],
  906. [
  907. 'offset' => 1,
  908. 'color' => '#2cc981'
  909. ]
  910. ]
  911. ]]
  912. ];
  913. $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series1, 'data' => $data['price']];//分类1值
  914. $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'line', 'itemStyle' => $series2, 'data' => $data['count'], 'yAxisIndex' => 1];//分类2值
  915. //统计总数上期
  916. $pre_total = $this->dao->preTotalFind($pre_datebefor, $pre_dateafter);
  917. if ($pre_total) {
  918. $chartdata['pre_cycle']['count'] = [
  919. 'data' => $pre_total['count'] ?: 0
  920. ];
  921. $chartdata['pre_cycle']['price'] = [
  922. 'data' => $pre_total['price'] ?: 0
  923. ];
  924. }
  925. //统计总数
  926. $total = $this->dao->preTotalFind($datebefor, $dateafter);
  927. if ($total) {
  928. $cha_count = intval($pre_total['count']) - intval($total['count']);
  929. $pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
  930. $chartdata['cycle']['count'] = [
  931. 'data' => $total['count'] ?: 0,
  932. 'percent' => round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
  933. 'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
  934. ];
  935. $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
  936. $pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
  937. $chartdata['cycle']['price'] = [
  938. 'data' => $total['price'] ?: 0,
  939. 'percent' => round(abs($cha_price) / $pre_total['price'] * 100, 2),
  940. 'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
  941. ];
  942. }
  943. return $chartdata;
  944. case 'week':
  945. $weekarray = array(['周日'], ['周一'], ['周二'], ['周三'], ['周四'], ['周五'], ['周六']);
  946. $datebefor = date('Y-m-d', strtotime('-1 week Monday'));
  947. $dateafter = date('Y-m-d', strtotime('-1 week Sunday'));
  948. // $order_list = $this->dao->orderAddTimeList($datebefor, $dateafter, 'week');
  949. //数据查询重新处理
  950. $new_order_list = [];
  951. // foreach ($order_list as $k => $v) {
  952. // $new_order_list[$v['day']] = $v;
  953. // }
  954. $now_datebefor = date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600));
  955. $now_dateafter = date('Y-m-d', strtotime("+1 day"));
  956. $now_order_list = $this->dao->nowOrderList($now_datebefor, $now_dateafter, 'week');
  957. //数据查询重新处理 key 变为当前值
  958. $new_now_order_list = [];
  959. foreach ($now_order_list as $k => $v) {
  960. $new_now_order_list[$v['day']] = $v;
  961. }
  962. foreach ($weekarray as $dk => $dd) {
  963. if (!empty($new_order_list[$dk])) {
  964. $weekarray[$dk]['pre'] = $new_order_list[$dk];
  965. } else {
  966. $weekarray[$dk]['pre'] = ['count' => 0, 'day' => $weekarray[$dk][0], 'price' => '0'];
  967. }
  968. if (!empty($new_now_order_list[$dk])) {
  969. $weekarray[$dk]['now'] = $new_now_order_list[$dk];
  970. } else {
  971. $weekarray[$dk]['now'] = ['count' => 0, 'day' => $weekarray[$dk][0], 'price' => '0'];
  972. }
  973. }
  974. $chartdata = [];
  975. $data = [];//临时
  976. $chartdata['yAxis']['maxnum'] = 0;//最大值数量
  977. $chartdata['yAxis']['maxprice'] = 0;//最大值金额
  978. foreach ($weekarray as $k => $v) {
  979. $data['day'][] = $v[0];
  980. $data['pre']['count'][] = $v['pre']['count'];
  981. $data['pre']['price'][] = round($v['pre']['price'], 2);
  982. $data['now']['count'][] = $v['now']['count'];
  983. $data['now']['price'][] = round($v['now']['price'], 2);
  984. if ($chartdata['yAxis']['maxnum'] < $v['pre']['count'] || $chartdata['yAxis']['maxnum'] < $v['now']['count']) {
  985. $chartdata['yAxis']['maxnum'] = $v['pre']['count'] > $v['now']['count'] ? $v['pre']['count'] : $v['now']['count'];//日最大订单数
  986. }
  987. if ($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']) {
  988. $chartdata['yAxis']['maxprice'] = $v['pre']['price'] > $v['now']['price'] ? $v['pre']['price'] : $v['now']['price'];//日最大金额
  989. }
  990. }
  991. $chartdata['legend'] = ['上周金额', '本周金额', '上周订单数', '本周订单数'];//分类
  992. $chartdata['xAxis'] = $data['day'];//X轴值
  993. $series1 = ['normal' => ['color' => [
  994. 'x' => 0, 'y' => 0, 'x2' => 0, 'y2' => 1,
  995. 'colorStops' => [
  996. [
  997. 'offset' => 0,
  998. 'color' => '#69cdff'
  999. ],
  1000. [
  1001. 'offset' => 0.5,
  1002. 'color' => '#3eb3f7'
  1003. ],
  1004. [
  1005. 'offset' => 1,
  1006. 'color' => '#1495eb'
  1007. ]
  1008. ]
  1009. ]]
  1010. ];
  1011. $series2 = ['normal' => ['color' => [
  1012. 'x' => 0, 'y' => 0, 'x2' => 0, 'y2' => 1,
  1013. 'colorStops' => [
  1014. [
  1015. 'offset' => 0,
  1016. 'color' => '#6fdeab'
  1017. ],
  1018. [
  1019. 'offset' => 0.5,
  1020. 'color' => '#44d693'
  1021. ],
  1022. [
  1023. 'offset' => 1,
  1024. 'color' => '#2cc981'
  1025. ]
  1026. ]
  1027. ]]
  1028. ];
  1029. $series3 = ['normal' => ['color' => [
  1030. 'x' => 0, 'y' => 0, 'x2' => 0, 'y2' => 1,
  1031. 'colorStops' => [
  1032. [
  1033. 'offset' => 0,
  1034. 'color' => '#69cdff'
  1035. ],
  1036. [
  1037. 'offset' => 0.5,
  1038. 'color' => '#3eb3f7'
  1039. ],
  1040. [
  1041. 'offset' => 1,
  1042. 'color' => '#1495eb'
  1043. ]
  1044. ]
  1045. ]]
  1046. ];
  1047. $series4 = ['normal' => ['color' => [
  1048. 'x' => 0, 'y' => 0, 'x2' => 0, 'y2' => 1,
  1049. 'colorStops' => [
  1050. [
  1051. 'offset' => 0,
  1052. 'color' => '#6fdeab'
  1053. ],
  1054. [
  1055. 'offset' => 0.5,
  1056. 'color' => '#44d693'
  1057. ],
  1058. [
  1059. 'offset' => 1,
  1060. 'color' => '#2cc981'
  1061. ]
  1062. ]
  1063. ]]
  1064. ];
  1065. $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series1, 'data' => $data['pre']['price']];//分类1值
  1066. $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'bar', 'itemStyle' => $series2, 'data' => $data['now']['price']];//分类1值
  1067. $chartdata['series'][] = ['name' => $chartdata['legend'][2], 'type' => 'line', 'itemStyle' => $series3, 'data' => $data['pre']['count'], 'yAxisIndex' => 1];//分类2值
  1068. $chartdata['series'][] = ['name' => $chartdata['legend'][3], 'type' => 'line', 'itemStyle' => $series4, 'data' => $data['now']['count'], 'yAxisIndex' => 1];//分类2值
  1069. //统计总数上期
  1070. $pre_total = $this->dao->preTotalFind($datebefor, $dateafter);
  1071. if ($pre_total) {
  1072. $chartdata['pre_cycle']['count'] = [
  1073. 'data' => $pre_total['count'] ?: 0
  1074. ];
  1075. $chartdata['pre_cycle']['price'] = [
  1076. 'data' => $pre_total['price'] ?: 0
  1077. ];
  1078. }
  1079. //统计总数
  1080. $total = $this->dao->preTotalFind($now_datebefor, $now_dateafter);
  1081. if ($total) {
  1082. $cha_count = intval($pre_total['count']) - intval($total['count']);
  1083. $pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
  1084. $chartdata['cycle']['count'] = [
  1085. 'data' => $total['count'] ?: 0,
  1086. 'percent' => round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
  1087. 'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
  1088. ];
  1089. $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
  1090. $pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
  1091. $chartdata['cycle']['price'] = [
  1092. 'data' => $total['price'] ?: 0,
  1093. 'percent' => round(abs($cha_price) / $pre_total['price'] * 100, 2),
  1094. 'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
  1095. ];
  1096. }
  1097. return $chartdata;
  1098. case 'month':
  1099. $weekarray = array('01' => ['1'], '02' => ['2'], '03' => ['3'], '04' => ['4'], '05' => ['5'], '06' => ['6'], '07' => ['7'], '08' => ['8'], '09' => ['9'], '10' => ['10'], '11' => ['11'], '12' => ['12'], '13' => ['13'], '14' => ['14'], '15' => ['15'], '16' => ['16'], '17' => ['17'], '18' => ['18'], '19' => ['19'], '20' => ['20'], '21' => ['21'], '22' => ['22'], '23' => ['23'], '24' => ['24'], '25' => ['25'], '26' => ['26'], '27' => ['27'], '28' => ['28'], '29' => ['29'], '30' => ['30'], '31' => ['31']);
  1100. $datebefor = date('Y-m-01', strtotime('-1 month'));
  1101. $dateafter = date('Y-m-d', strtotime(date('Y-m-01')));
  1102. $order_list = $this->dao->orderAddTimeList($datebefor, $dateafter, "month");
  1103. //数据查询重新处理
  1104. $new_order_list = [];
  1105. foreach ($order_list as $k => $v) {
  1106. $new_order_list[$v['day']] = $v;
  1107. }
  1108. $now_datebefor = date('Y-m-01');
  1109. $now_dateafter = date('Y-m-d', strtotime("+1 day"));
  1110. $now_order_list = $this->dao->nowOrderList($now_datebefor, $now_dateafter, "month");
  1111. //数据查询重新处理 key 变为当前值
  1112. $new_now_order_list = [];
  1113. foreach ($now_order_list as $k => $v) {
  1114. $new_now_order_list[$v['day']] = $v;
  1115. }
  1116. foreach ($weekarray as $dk => $dd) {
  1117. if (!empty($new_order_list[$dk])) {
  1118. $weekarray[$dk]['pre'] = $new_order_list[$dk];
  1119. } else {
  1120. $weekarray[$dk]['pre'] = ['count' => 0, 'day' => $weekarray[$dk][0], 'price' => '0'];
  1121. }
  1122. if (!empty($new_now_order_list[$dk])) {
  1123. $weekarray[$dk]['now'] = $new_now_order_list[$dk];
  1124. } else {
  1125. $weekarray[$dk]['now'] = ['count' => 0, 'day' => $weekarray[$dk][0], 'price' => '0'];
  1126. }
  1127. }
  1128. $chartdata = [];
  1129. $data = [];//临时
  1130. $chartdata['yAxis']['maxnum'] = 0;//最大值数量
  1131. $chartdata['yAxis']['maxprice'] = 0;//最大值金额
  1132. foreach ($weekarray as $k => $v) {
  1133. $data['day'][] = $v[0];
  1134. $data['pre']['count'][] = $v['pre']['count'];
  1135. $data['pre']['price'][] = round($v['pre']['price'], 2);
  1136. $data['now']['count'][] = $v['now']['count'];
  1137. $data['now']['price'][] = round($v['now']['price'], 2);
  1138. if ($chartdata['yAxis']['maxnum'] < $v['pre']['count'] || $chartdata['yAxis']['maxnum'] < $v['now']['count']) {
  1139. $chartdata['yAxis']['maxnum'] = $v['pre']['count'] > $v['now']['count'] ? $v['pre']['count'] : $v['now']['count'];//日最大订单数
  1140. }
  1141. if ($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']) {
  1142. $chartdata['yAxis']['maxprice'] = $v['pre']['price'] > $v['now']['price'] ? $v['pre']['price'] : $v['now']['price'];//日最大金额
  1143. }
  1144. }
  1145. $chartdata['legend'] = ['上月金额', '本月金额', '上月订单数', '本月订单数'];//分类
  1146. $chartdata['xAxis'] = $data['day'];//X轴值
  1147. $series1 = ['normal' => ['color' => [
  1148. 'x' => 0, 'y' => 0, 'x2' => 0, 'y2' => 1,
  1149. 'colorStops' => [
  1150. [
  1151. 'offset' => 0,
  1152. 'color' => '#69cdff'
  1153. ],
  1154. [
  1155. 'offset' => 0.5,
  1156. 'color' => '#3eb3f7'
  1157. ],
  1158. [
  1159. 'offset' => 1,
  1160. 'color' => '#1495eb'
  1161. ]
  1162. ]
  1163. ]]
  1164. ];
  1165. $series2 = ['normal' => ['color' => [
  1166. 'x' => 0, 'y' => 0, 'x2' => 0, 'y2' => 1,
  1167. 'colorStops' => [
  1168. [
  1169. 'offset' => 0,
  1170. 'color' => '#6fdeab'
  1171. ],
  1172. [
  1173. 'offset' => 0.5,
  1174. 'color' => '#44d693'
  1175. ],
  1176. [
  1177. 'offset' => 1,
  1178. 'color' => '#2cc981'
  1179. ]
  1180. ]
  1181. ]]
  1182. ];
  1183. $series3 = ['normal' => ['color' => [
  1184. 'x' => 0, 'y' => 0, 'x2' => 0, 'y2' => 1,
  1185. 'colorStops' => [
  1186. [
  1187. 'offset' => 0,
  1188. 'color' => '#69cdff'
  1189. ],
  1190. [
  1191. 'offset' => 0.5,
  1192. 'color' => '#3eb3f7'
  1193. ],
  1194. [
  1195. 'offset' => 1,
  1196. 'color' => '#1495eb'
  1197. ]
  1198. ]
  1199. ]]
  1200. ];
  1201. $series4 = ['normal' => ['color' => [
  1202. 'x' => 0, 'y' => 0, 'x2' => 0, 'y2' => 1,
  1203. 'colorStops' => [
  1204. [
  1205. 'offset' => 0,
  1206. 'color' => '#6fdeab'
  1207. ],
  1208. [
  1209. 'offset' => 0.5,
  1210. 'color' => '#44d693'
  1211. ],
  1212. [
  1213. 'offset' => 1,
  1214. 'color' => '#2cc981'
  1215. ]
  1216. ]
  1217. ]]
  1218. ];
  1219. $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series1, 'data' => $data['pre']['price']];//分类1值
  1220. $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'bar', 'itemStyle' => $series2, 'data' => $data['now']['price']];//分类1值
  1221. $chartdata['series'][] = ['name' => $chartdata['legend'][2], 'type' => 'line', 'itemStyle' => $series3, 'data' => $data['pre']['count'], 'yAxisIndex' => 1];//分类2值
  1222. $chartdata['series'][] = ['name' => $chartdata['legend'][3], 'type' => 'line', 'itemStyle' => $series4, 'data' => $data['now']['count'], 'yAxisIndex' => 1];//分类2值
  1223. //统计总数上期
  1224. $pre_total = $this->dao->preTotalFind($datebefor, $dateafter);
  1225. if ($pre_total) {
  1226. $chartdata['pre_cycle']['count'] = [
  1227. 'data' => $pre_total['count'] ?: 0
  1228. ];
  1229. $chartdata['pre_cycle']['price'] = [
  1230. 'data' => $pre_total['price'] ?: 0
  1231. ];
  1232. }
  1233. //统计总数
  1234. $total = $this->dao->preTotalFind($now_datebefor, $now_dateafter);
  1235. if ($total) {
  1236. $cha_count = intval($pre_total['count']) - intval($total['count']);
  1237. $pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
  1238. $chartdata['cycle']['count'] = [
  1239. 'data' => $total['count'] ?: 0,
  1240. 'percent' => round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
  1241. 'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
  1242. ];
  1243. $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
  1244. $pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
  1245. $chartdata['cycle']['price'] = [
  1246. 'data' => $total['price'] ?: 0,
  1247. 'percent' => round(abs($cha_price) / $pre_total['price'] * 100, 2),
  1248. 'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
  1249. ];
  1250. }
  1251. return $chartdata;
  1252. case 'year':
  1253. $weekarray = array('01' => ['一月'], '02' => ['二月'], '03' => ['三月'], '04' => ['四月'], '05' => ['五月'], '06' => ['六月'], '07' => ['七月'], '08' => ['八月'], '09' => ['九月'], '10' => ['十月'], '11' => ['十一月'], '12' => ['十二月']);
  1254. $datebefor = date('Y-01-01', strtotime('-1 year'));
  1255. $dateafter = date('Y-12-31', strtotime('-1 year'));
  1256. $order_list = $this->dao->orderAddTimeList($datebefor, $dateafter, 'year');
  1257. //数据查询重新处理
  1258. $new_order_list = [];
  1259. foreach ($order_list as $k => $v) {
  1260. $new_order_list[$v['day']] = $v;
  1261. }
  1262. $now_datebefor = date('Y-01-01');
  1263. $now_dateafter = date('Y-12-31 23:59:59');
  1264. $now_order_list = $this->dao->nowOrderList($now_datebefor, $now_dateafter, 'year');
  1265. //数据查询重新处理 key 变为当前值
  1266. $new_now_order_list = [];
  1267. foreach ($now_order_list as $k => $v) {
  1268. $new_now_order_list[$v['day']] = $v;
  1269. }
  1270. foreach ($weekarray as $dk => $dd) {
  1271. if (!empty($new_order_list[$dk])) {
  1272. $weekarray[$dk]['pre'] = $new_order_list[$dk];
  1273. } else {
  1274. $weekarray[$dk]['pre'] = ['count' => 0, 'day' => $weekarray[$dk][0], 'price' => '0'];
  1275. }
  1276. if (!empty($new_now_order_list[$dk])) {
  1277. $weekarray[$dk]['now'] = $new_now_order_list[$dk];
  1278. } else {
  1279. $weekarray[$dk]['now'] = ['count' => 0, 'day' => $weekarray[$dk][0], 'price' => '0'];
  1280. }
  1281. }
  1282. $chartdata = [];
  1283. $data = [];//临时
  1284. $chartdata['yAxis']['maxnum'] = 0;//最大值数量
  1285. $chartdata['yAxis']['maxprice'] = 0;//最大值金额
  1286. foreach ($weekarray as $k => $v) {
  1287. $data['day'][] = $v[0];
  1288. $data['pre']['count'][] = $v['pre']['count'];
  1289. $data['pre']['price'][] = round($v['pre']['price'], 2);
  1290. $data['now']['count'][] = $v['now']['count'];
  1291. $data['now']['price'][] = round($v['now']['price'], 2);
  1292. if ($chartdata['yAxis']['maxnum'] < $v['pre']['count'] || $chartdata['yAxis']['maxnum'] < $v['now']['count']) {
  1293. $chartdata['yAxis']['maxnum'] = $v['pre']['count'] > $v['now']['count'] ? $v['pre']['count'] : $v['now']['count'];//日最大订单数
  1294. }
  1295. if ($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']) {
  1296. $chartdata['yAxis']['maxprice'] = $v['pre']['price'] > $v['now']['price'] ? $v['pre']['price'] : $v['now']['price'];//日最大金额
  1297. }
  1298. }
  1299. $chartdata['legend'] = ['去年金额', '今年金额', '去年订单数', '今年订单数'];//分类
  1300. $chartdata['xAxis'] = $data['day'];//X轴值
  1301. $series1 = ['normal' => ['color' => [
  1302. 'x' => 0, 'y' => 0, 'x2' => 0, 'y2' => 1,
  1303. 'colorStops' => [
  1304. [
  1305. 'offset' => 0,
  1306. 'color' => '#69cdff'
  1307. ],
  1308. [
  1309. 'offset' => 0.5,
  1310. 'color' => '#3eb3f7'
  1311. ],
  1312. [
  1313. 'offset' => 1,
  1314. 'color' => '#1495eb'
  1315. ]
  1316. ]
  1317. ]]
  1318. ];
  1319. $series2 = ['normal' => ['color' => [
  1320. 'x' => 0, 'y' => 0, 'x2' => 0, 'y2' => 1,
  1321. 'colorStops' => [
  1322. [
  1323. 'offset' => 0,
  1324. 'color' => '#6fdeab'
  1325. ],
  1326. [
  1327. 'offset' => 0.5,
  1328. 'color' => '#44d693'
  1329. ],
  1330. [
  1331. 'offset' => 1,
  1332. 'color' => '#2cc981'
  1333. ]
  1334. ]
  1335. ]]
  1336. ];
  1337. $series3 = ['normal' => ['color' => [
  1338. 'x' => 0, 'y' => 0, 'x2' => 0, 'y2' => 1,
  1339. 'colorStops' => [
  1340. [
  1341. 'offset' => 0,
  1342. 'color' => '#69cdff'
  1343. ],
  1344. [
  1345. 'offset' => 0.5,
  1346. 'color' => '#3eb3f7'
  1347. ],
  1348. [
  1349. 'offset' => 1,
  1350. 'color' => '#1495eb'
  1351. ]
  1352. ]
  1353. ]]
  1354. ];
  1355. $series4 = ['normal' => ['color' => [
  1356. 'x' => 0, 'y' => 0, 'x2' => 0, 'y2' => 1,
  1357. 'colorStops' => [
  1358. [
  1359. 'offset' => 0,
  1360. 'color' => '#6fdeab'
  1361. ],
  1362. [
  1363. 'offset' => 0.5,
  1364. 'color' => '#44d693'
  1365. ],
  1366. [
  1367. 'offset' => 1,
  1368. 'color' => '#2cc981'
  1369. ]
  1370. ]
  1371. ]]
  1372. ];
  1373. $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series1, 'data' => $data['pre']['price']];//分类1值
  1374. $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'bar', 'itemStyle' => $series2, 'data' => $data['now']['price']];//分类1值
  1375. $chartdata['series'][] = ['name' => $chartdata['legend'][2], 'type' => 'line', 'itemStyle' => $series3, 'data' => $data['pre']['count'], 'yAxisIndex' => 1];//分类2值
  1376. $chartdata['series'][] = ['name' => $chartdata['legend'][3], 'type' => 'line', 'itemStyle' => $series4, 'data' => $data['now']['count'], 'yAxisIndex' => 1];//分类2值
  1377. //统计总数上期
  1378. $pre_total = $this->dao->preTotalFind($datebefor, $dateafter);
  1379. if ($pre_total) {
  1380. $chartdata['pre_cycle']['count'] = [
  1381. 'data' => $pre_total['count'] ?: 0
  1382. ];
  1383. $chartdata['pre_cycle']['price'] = [
  1384. 'data' => $pre_total['price'] ?: 0
  1385. ];
  1386. }
  1387. //统计总数
  1388. $total = $this->dao->preTotalFind($now_datebefor, $now_dateafter);
  1389. if ($total) {
  1390. $cha_count = intval($pre_total['count']) - intval($total['count']);
  1391. $pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
  1392. $chartdata['cycle']['count'] = [
  1393. 'data' => $total['count'] ?: 0,
  1394. 'percent' => round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
  1395. 'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
  1396. ];
  1397. $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
  1398. $pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
  1399. $chartdata['cycle']['price'] = [
  1400. 'data' => $total['price'] ?: 0,
  1401. 'percent' => round(abs($cha_price) / $pre_total['price'] * 100, 2),
  1402. 'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
  1403. ];
  1404. }
  1405. return $chartdata;
  1406. default:
  1407. break;
  1408. }
  1409. }
  1410. /**
  1411. * 获取订单数量
  1412. * @return int
  1413. */
  1414. public function storeOrderCount()
  1415. {
  1416. return $this->dao->storeOrderCount();
  1417. }
  1418. /**
  1419. * 新订单ID
  1420. * @param $status
  1421. * @return array
  1422. */
  1423. public function newOrderId($status)
  1424. {
  1425. return $this->dao->search(['status' => $status, 'is_remind' => 0])->column('order_id', 'id');
  1426. }
  1427. /**
  1428. * 新订单修改
  1429. * @param $newOrderId
  1430. * @return \crmeb\basic\BaseModel
  1431. */
  1432. public function newOrderUpdate($newOrderId)
  1433. {
  1434. return $this->dao->newOrderUpdates($newOrderId);
  1435. }
  1436. /**
  1437. * 增长率
  1438. * @param $left
  1439. * @param $right
  1440. * @return int|string
  1441. */
  1442. public function growth($nowValue, $lastValue)
  1443. {
  1444. if ($lastValue == 0 && $nowValue == 0) return 0;
  1445. if ($lastValue == 0) return bcmul((string)$nowValue, '100', 2);
  1446. if ($nowValue == 0) return bcdiv(bcsub($nowValue, $lastValue, 2), $lastValue, 4) * 100;
  1447. return bcmul(bcdiv((bcsub($nowValue, $lastValue, 2)), $lastValue, 4), 100, 2);
  1448. }
  1449. /**
  1450. * 后台首页顶部统计
  1451. * @return array
  1452. * @author 吴汐
  1453. * @email 442384644@qq.com
  1454. * @date 2023/04/03
  1455. */
  1456. public function homeStatics()
  1457. {
  1458. /** @var UserServices $userService */
  1459. $userService = app()->make(UserServices::class);
  1460. /** @var StoreProductLogServices $productLogServices */
  1461. $productLogServices = app()->make(StoreProductLogServices::class);
  1462. //TODO 销售额
  1463. //今日销售额
  1464. $today_sales = $this->dao->todaySales('today');
  1465. //昨日销售额
  1466. $yesterday_sales = $this->dao->todaySales('yesterday');
  1467. //日同比
  1468. $sales_today_ratio = $this->growth($today_sales, $yesterday_sales);
  1469. //总销售额
  1470. $total_sales = $this->dao->totalSales('month');
  1471. $sales = [
  1472. 'today' => $today_sales,
  1473. 'yesterday' => $yesterday_sales,
  1474. 'today_ratio' => $sales_today_ratio,
  1475. 'total' => $total_sales . '元',
  1476. 'date' => '今日'
  1477. ];
  1478. //TODO:用户访问量
  1479. //今日访问量
  1480. $today_visits = $productLogServices->count(['time' => 'today', 'type' => 'visit']);
  1481. //昨日访问量
  1482. $yesterday_visits = $productLogServices->count(['time' => 'yesterday', 'type' => 'visit']);
  1483. //日同比
  1484. $visits_today_ratio = $this->growth($today_visits, $yesterday_visits);
  1485. //总访问量
  1486. $total_visits = $productLogServices->count(['time' => 'month', 'type' => 'visit']);
  1487. $visits = [
  1488. 'today' => $today_visits,
  1489. 'yesterday' => $yesterday_visits,
  1490. 'today_ratio' => $visits_today_ratio,
  1491. 'total' => $total_visits . 'Pv',
  1492. 'date' => '今日'
  1493. ];
  1494. //TODO 订单量
  1495. //今日订单量
  1496. $today_order = $this->dao->todayOrderVisit('today', 1);
  1497. //昨日订单量
  1498. $yesterday_order = $this->dao->todayOrderVisit('yesterday', 1);
  1499. //订单日同比
  1500. $order_today_ratio = $this->growth($today_order, $yesterday_order);
  1501. //总订单量
  1502. $total_order = $this->dao->count(['time' => 'month', 'paid' => 1, 'refund_status' => 0, 'pid' => 0]);
  1503. $order = [
  1504. 'today' => $today_order,
  1505. 'yesterday' => $yesterday_order,
  1506. 'today_ratio' => $order_today_ratio,
  1507. 'total' => $total_order . '单',
  1508. 'date' => '今日'
  1509. ];
  1510. //TODO 用户
  1511. //今日新增用户
  1512. $today_user = $userService->todayAddVisits('today', 1);
  1513. //昨日新增用户
  1514. $yesterday_user = $userService->todayAddVisits('yesterday', 1);
  1515. //新增用户日同比
  1516. $user_today_ratio = $this->growth($today_user, $yesterday_user);
  1517. //所有用户
  1518. $total_user = $userService->count(['time' => 'month']);
  1519. $user = [
  1520. 'today' => $today_user,
  1521. 'yesterday' => $yesterday_user,
  1522. 'today_ratio' => $user_today_ratio,
  1523. 'total' => $total_user . '人',
  1524. 'date' => '今日'
  1525. ];
  1526. $info = array_values(compact('sales', 'visits', 'order', 'user'));
  1527. $info[0]['title'] = '销售额';
  1528. $info[1]['title'] = '用户访问量';
  1529. $info[2]['title'] = '订单量';
  1530. $info[3]['title'] = '新增用户';
  1531. $info[0]['total_name'] = '本月销售额';
  1532. $info[1]['total_name'] = '本月访问量';
  1533. $info[2]['total_name'] = '本月订单量';
  1534. $info[3]['total_name'] = '本月新增用户';
  1535. return $info;
  1536. }
  1537. /**
  1538. * 订单小票打印
  1539. * @param int $id
  1540. * @param bool $start
  1541. * @return bool|void
  1542. * @throws \think\db\exception\DataNotFoundException
  1543. * @throws \think\db\exception\DbException
  1544. * @throws \think\db\exception\ModelNotFoundException
  1545. * @throws \Exception
  1546. */
  1547. public function orderPrintTicket(int $id)
  1548. {
  1549. $order = $this->get($id);
  1550. if (!$order) {
  1551. throw new AdminException(400118);
  1552. }
  1553. /** @var StoreOrderCartInfoServices $cartServices */
  1554. $cartServices = app()->make(StoreOrderCartInfoServices::class);
  1555. $product = $cartServices->getCartInfoPrintProduct($order['id']);
  1556. if (!$product) {
  1557. throw new AdminException(400463);
  1558. }
  1559. $switch = (bool)sys_config('pay_success_printing_switch');
  1560. if (!$switch) {
  1561. throw new AdminException(400464);
  1562. }
  1563. if (sys_config('print_type', 1) == 1) {
  1564. $name = 'yi_lian_yun';
  1565. $configData = [
  1566. 'clientId' => sys_config('printing_client_id', ''),
  1567. 'apiKey' => sys_config('printing_api_key', ''),
  1568. 'partner' => sys_config('develop_id', ''),
  1569. 'terminal' => sys_config('terminal_number', '')
  1570. ];
  1571. if (!$configData['clientId'] || !$configData['apiKey'] || !$configData['partner'] || !$configData['terminal']) {
  1572. throw new AdminException(400465);
  1573. }
  1574. } else {
  1575. $name = 'fei_e_yun';
  1576. $configData = [
  1577. 'feyUser' => sys_config('fey_user', ''),
  1578. 'feyUkey' => sys_config('fey_ukey', ''),
  1579. 'feySn' => sys_config('fey_sn', '')
  1580. ];
  1581. if (!$configData['feyUser'] || !$configData['feyUkey'] || !$configData['feySn']) {
  1582. throw new AdminException(400465);
  1583. }
  1584. }
  1585. $printer = new Printer($name, $configData);
  1586. $res = $printer->setPrinterContent([
  1587. 'name' => sys_config('site_name'),
  1588. 'url' => sys_config('site_url'),
  1589. 'orderInfo' => is_object($order) ? $order->toArray() : $order,
  1590. 'product' => $product
  1591. ])->startPrinter();
  1592. if (!$res) {
  1593. throw new AdminException($printer->getError());
  1594. }
  1595. return true;
  1596. }
  1597. /**
  1598. * 获取订单确认数据
  1599. * @param array $user
  1600. * @param $cartId
  1601. * @param bool $new
  1602. * @param int $addressId
  1603. * @param int $shipping_type
  1604. * @return array
  1605. * @throws \Psr\SimpleCache\InvalidArgumentException
  1606. * @throws \think\db\exception\DataNotFoundException
  1607. * @throws \think\db\exception\DbException
  1608. * @throws \think\db\exception\ModelNotFoundException
  1609. */
  1610. public function getOrderConfirmData(array $user, $cartId, bool $new, int $addressId, int $shipping_type = 1)
  1611. {
  1612. $addr = [];
  1613. /** @var UserAddressServices $addressServices */
  1614. $addressServices = app()->make(UserAddressServices::class);
  1615. if ($addressId) {
  1616. $addr = $addressServices->getAddress($addressId);
  1617. }
  1618. //没传地址id或地址已删除未找到 ||获取默认地址
  1619. if (!$addr) {
  1620. $addr = $addressServices->getUserDefaultAddress((int)$user['uid']);
  1621. }
  1622. if ($addr) {
  1623. $addr = $addr->toArray();
  1624. } else {
  1625. $addr = [];
  1626. }
  1627. if ($shipping_type == 2) $addr = [];
  1628. /** @var StoreCartServices $cartServices */
  1629. $cartServices = app()->make(StoreCartServices::class);
  1630. $cartGroup = $cartServices->getUserProductCartListV1($user['uid'], $cartId, $new, $addr, $shipping_type);
  1631. $data = [];
  1632. $data['storeFreePostage'] = $storeFreePostage = floatval(sys_config('store_free_postage')) ?: 0;//满额包邮金额
  1633. $validCartInfo = $cartGroup['valid'];
  1634. /** @var StoreOrderComputedServices $computedServices */
  1635. $computedServices = app()->make(StoreOrderComputedServices::class);
  1636. $priceGroup = $computedServices->getOrderPriceGroup($storeFreePostage, $validCartInfo, $addr, $user, $shipping_type);
  1637. $validCartInfo = $priceGroup['cartInfo'] ?? $validCartInfo;
  1638. $other = [
  1639. 'offlinePostage' => sys_config('offline_postage'),
  1640. 'integralRatio' => sys_config('integral_ratio')
  1641. ];
  1642. $cartIdA = explode(',', $cartId);
  1643. $seckill_id = 0;
  1644. $combination_id = 0;
  1645. $bargain_id = 0;
  1646. $advance_id = 0;
  1647. if (count($cartIdA) == 1) {
  1648. $seckill_id = $cartGroup['deduction']['seckill_id'] ?? 0;
  1649. $combination_id = $cartGroup['deduction']['combination_id'] ?? 0;
  1650. $bargain_id = $cartGroup['deduction']['bargain_id'] ?? 0;
  1651. $advance_id = $cartGroup['deduction']['advance_id'] ?? 0;
  1652. }
  1653. $data['valid_count'] = count($validCartInfo);
  1654. $data['virtual_type'] = $data['valid_count'] ? (int)$validCartInfo[0]['productInfo']['virtual_type'] > 0 : 0;
  1655. $data['deduction'] = $seckill_id || $combination_id || $bargain_id || $advance_id;
  1656. $data['addressInfo'] = $addr;
  1657. $data['seckill_id'] = $seckill_id;
  1658. $data['combination_id'] = $combination_id;
  1659. $data['bargain_id'] = $bargain_id;
  1660. $data['advance_id'] = $advance_id;
  1661. $data['cartInfo'] = $cartGroup['cartInfo'];
  1662. $data['custom_form'] = json_decode($cartGroup['cartInfo'][0]['productInfo']['custom_form'], true) ?? [];
  1663. $data['priceGroup'] = $priceGroup;
  1664. $data['orderKey'] = $this->cacheOrderInfo($user['uid'], $validCartInfo, $priceGroup, $other);
  1665. $data['offlinePostage'] = $other['offlinePostage'];
  1666. /** @var UserLevelServices $levelServices */
  1667. $levelServices = app()->make(UserLevelServices::class);
  1668. $userLevel = $levelServices->getUerLevelInfoByUid($user['uid']);
  1669. if (isset($user['pwd'])) unset($user['pwd']);
  1670. $user['vip'] = $userLevel !== false;
  1671. if ($user['vip']) {
  1672. $user['vip_id'] = $userLevel['id'] ?? 0;
  1673. $user['discount'] = $userLevel['discount'] ?? 0;
  1674. }
  1675. $data['userInfo'] = $user;
  1676. $data['integralRatio'] = $other['integralRatio'];
  1677. $data['offline_pay_status'] = (int)sys_config('offline_pay_status') ?? (int)2;
  1678. $data['yue_pay_status'] = (int)sys_config('balance_func_status') && (int)sys_config('yue_pay_status') == 1 ? (int)1 : (int)2;//余额支付 1 开启 2 关闭
  1679. $data['pay_weixin_open'] = sys_config('pay_weixin_open', '0') != '0';//微信支付 1 开启 0 关闭
  1680. $data['friend_pay_status'] = (int)sys_config('friend_pay_status') ?? 0;//好友代付 1 开启 0 关闭
  1681. $data['store_self_mention'] = (int)sys_config('store_self_mention') ?? 0;//门店自提是否开启
  1682. /** @var SystemStoreServices $systemStoreServices */
  1683. $systemStoreServices = app()->make(SystemStoreServices::class);
  1684. $store_count = $systemStoreServices->count(['type' => 0]);
  1685. $data['store_self_mention'] = $data['store_self_mention'] && $store_count;
  1686. $data['ali_pay_status'] = sys_config('ali_pay_status', '0') != '0';//支付包支付 1 开启 0 关闭
  1687. $data['system_store'] = [];//门店信息
  1688. /** @var UserInvoiceServices $userInvoice */
  1689. $userInvoice = app()->make(UserInvoiceServices::class);
  1690. $invoice_func = $userInvoice->invoiceFuncStatus();
  1691. $data['invoice_func'] = $invoice_func['invoice_func'];
  1692. $data['special_invoice'] = $invoice_func['special_invoice'];
  1693. /** @var UserBillServices $userBillServices */
  1694. $userBillServices = app()->make(UserBillServices::class);
  1695. $data['usable_integral'] = bcsub((string)$user['integral'], (string)$userBillServices->getBillSum(['uid' => $user['uid'], 'is_frozen' => 1]), 0);
  1696. $data['integral_open'] = sys_config('integral_ratio', 0) > 0;
  1697. return $data;
  1698. }
  1699. /**
  1700. * 缓存订单信息
  1701. * @param $uid
  1702. * @param $cartInfo
  1703. * @param $priceGroup
  1704. * @param array $other
  1705. * @param int $cacheTime
  1706. * @return string
  1707. * @throws \Psr\SimpleCache\InvalidArgumentException
  1708. */
  1709. public function cacheOrderInfo($uid, $cartInfo, $priceGroup, $other = [], $cacheTime = 600)
  1710. {
  1711. $key = $this->getCacheKey();
  1712. CacheService::set('user_order_' . $uid . $key, compact('cartInfo', 'priceGroup', 'other'), $cacheTime);
  1713. return $key;
  1714. }
  1715. /**
  1716. * 使用雪花算法生成订单ID
  1717. * @return string
  1718. * @throws \Exception
  1719. */
  1720. public function getCacheKey(string $prefix = '')
  1721. {
  1722. $snowflake = new \Godruoyi\Snowflake\Snowflake();
  1723. //32位
  1724. if (PHP_INT_SIZE == 4) {
  1725. $id = abs($snowflake->id());
  1726. } else {
  1727. $id = $snowflake->setStartTimeStamp(strtotime('2020-06-05') * 1000)->id();
  1728. }
  1729. return $prefix . $id;
  1730. }
  1731. /**获取用户购买活动产品的次数
  1732. * @param $uid
  1733. * @param $seckill_id
  1734. * @return int
  1735. */
  1736. public function activityProductCount(array $where)
  1737. {
  1738. return $this->dao->count($where);
  1739. }
  1740. /**
  1741. * 获取订单缓存信息
  1742. * @param int $uid
  1743. * @param string $key
  1744. * @return |null
  1745. */
  1746. public function getCacheOrderInfo(int $uid, string $key)
  1747. {
  1748. $cacheName = 'user_order_' . $uid . $key;
  1749. if (!CacheService::has($cacheName)) return null;
  1750. return CacheService::get($cacheName);
  1751. }
  1752. /**
  1753. * 获取拼团的订单id
  1754. * @param int $pid
  1755. * @param int $uid
  1756. * @return mixed
  1757. */
  1758. public function getStoreIdPink(int $pid, int $uid)
  1759. {
  1760. return $this->dao->value(['uid' => $uid, 'pink_id' => $pid, 'is_del' => 0], 'order_id');
  1761. }
  1762. /**
  1763. * 判断当前订单中是否有拼团
  1764. * @param int $pid
  1765. * @param int $uid
  1766. * @return int
  1767. */
  1768. public function getIsOrderPink($pid = 0, $uid = 0)
  1769. {
  1770. return $this->dao->count(['uid' => $uid, 'pink_id' => $pid, 'refund_status' => 0, 'is_del' => 0]);
  1771. }
  1772. /**
  1773. * 判断支付方式是否开启
  1774. * @param $payType
  1775. * @return bool
  1776. */
  1777. public function checkPaytype(string $payType)
  1778. {
  1779. $res = false;
  1780. switch ($payType) {
  1781. case PayServices::WEIXIN_PAY:
  1782. $res = sys_config('pay_weixin_open', '0') != '0';
  1783. break;
  1784. case PayServices::YUE_PAY:
  1785. $res = sys_config('balance_func_status') && sys_config('yue_pay_status') == 1;
  1786. break;
  1787. case 'offline':
  1788. $res = sys_config('offline_pay_status') == 1;
  1789. break;
  1790. case PayServices::ALIAPY_PAY:
  1791. $res = sys_config('ali_pay_status', '0') != '0';
  1792. break;
  1793. case PayServices::FRIEND:
  1794. $res = sys_config('friend_pay_status', 1) == 1;
  1795. break;
  1796. case PayServices::ALLIN_PAY:
  1797. $res = sys_config('allin_pay_status') == 1;
  1798. }
  1799. return $res;
  1800. }
  1801. /**
  1802. * 修改支付方式为线下支付
  1803. * @param string $orderId
  1804. * @return bool|\crmeb\basic\BaseModel
  1805. */
  1806. public function setOrderTypePayOffline(string $orderId)
  1807. {
  1808. if (($count = strpos($orderId, '_')) !== false) {
  1809. $orderId = substr($orderId, $count + 1);
  1810. }
  1811. if (sys_config('offline_postage', 0) == 1) {
  1812. $orderInfo = $this->dao->get(['order_id' => $orderId]);
  1813. $cartInfoService = app()->make(StoreOrderCartInfoServices::class);
  1814. $cartInfo = $cartInfoService->getColumn(['oid' => $orderInfo['id']], 'cart_info', 'id');
  1815. foreach ($cartInfo as $key => &$item) {
  1816. $item_arr = json_decode($item, true);
  1817. $item_arr['postage_price'] = $item_arr['origin_postage_price'] = 0;
  1818. $cartInfoService->update(['id' => $key], ['cart_info' => json_encode($item_arr)]);
  1819. }
  1820. return $this->dao->update($orderId, [
  1821. 'pay_type' => 'offline',
  1822. 'pay_price' => bcsub((string)$orderInfo['pay_price'], (string)$orderInfo['pay_postage'], 2),
  1823. 'pay_postage' => 0
  1824. ], 'order_id');
  1825. }
  1826. return $this->dao->update($orderId, ['pay_type' => 'offline'], 'order_id');
  1827. }
  1828. /**
  1829. * 删除订单
  1830. * @param string $uni
  1831. * @param int $uid
  1832. * @return bool
  1833. * @throws \Psr\SimpleCache\InvalidArgumentException
  1834. */
  1835. public function removeOrder(string $uni, int $uid)
  1836. {
  1837. $order = $this->getUserOrderDetail($uni, $uid);
  1838. if (!$order) {
  1839. throw new ApiException(410173);
  1840. }
  1841. $order = $this->tidyOrder($order);
  1842. if ($order['_status']['_type'] != 0 && $order['_status']['_type'] != -2 && $order['_status']['_type'] != 4)
  1843. throw new ApiException(410256);
  1844. $order->is_del = 1;
  1845. /** @var StoreOrderStatusServices $statusService */
  1846. $statusService = app()->make(StoreOrderStatusServices::class);
  1847. $res = $statusService->save([
  1848. 'oid' => $order['id'],
  1849. 'change_type' => 'remove_order',
  1850. 'change_message' => '删除订单',
  1851. 'change_time' => time()
  1852. ]);
  1853. if ($order->save() && $res) {
  1854. return true;
  1855. } else
  1856. throw new ApiException(100020);
  1857. }
  1858. /**
  1859. * 取消订单
  1860. * @param $order_id
  1861. * @param $uid
  1862. * @return bool|void
  1863. * @throws \think\db\exception\DataNotFoundException
  1864. * @throws \think\db\exception\DbException
  1865. * @throws \think\db\exception\ModelNotFoundException
  1866. */
  1867. public function cancelOrder($order_id, int $uid)
  1868. {
  1869. $order = $this->dao->getOne(['order_id' => $order_id, 'uid' => $uid, 'is_del' => 0]);
  1870. if (!$order) {
  1871. throw new ApiException(410173);
  1872. }
  1873. if ($order->paid) {
  1874. throw new ApiException(410257);
  1875. }
  1876. /** @var StoreOrderCartInfoServices $cartServices */
  1877. $cartServices = app()->make(StoreOrderCartInfoServices::class);
  1878. $cartInfo = $cartServices->getOrderCartInfo($order['id']);
  1879. /** @var StoreOrderRefundServices $refundServices */
  1880. $refundServices = app()->make(StoreOrderRefundServices::class);
  1881. $this->transaction(function () use ($refundServices, $order) {
  1882. $res = $refundServices->integralAndCouponBack($order, 'cancel') && $refundServices->regressionStock($order);
  1883. $order->is_del = 1;
  1884. if (!($res && $order->save())) {
  1885. throw new ApiException(100020);
  1886. }
  1887. });
  1888. //自定义事件-订单取消
  1889. event('CustomEventListener', ['order_cancel', [
  1890. 'uid' => $uid,
  1891. 'id' => $order['id'],
  1892. 'order_id' => $order_id,
  1893. 'real_name' => $order['id'],
  1894. 'user_phone' => $order['id'],
  1895. 'user_address' => $order['id'],
  1896. 'total_num' => $order['id'],
  1897. 'pay_price' => $order['id'],
  1898. 'deduction_price' => $order['id'],
  1899. 'coupon_price' => $order['id'],
  1900. 'cancel_time' => date('Y-m-d H:i:s'),
  1901. ]]);
  1902. return true;
  1903. }
  1904. /**
  1905. * 判断订单完成
  1906. * @param StoreProductReplyServices $replyServices
  1907. * @param array $uniqueList
  1908. * @param $oid
  1909. * @return mixed
  1910. */
  1911. public function checkOrderOver($replyServices, array $uniqueList, $oid)
  1912. {
  1913. //订单商品全部评价完成
  1914. $replyServices->count(['unique' => $uniqueList, 'oid' => $oid]);
  1915. if ($replyServices->count(['unique' => $uniqueList, 'oid' => $oid]) == count($uniqueList)) {
  1916. $res = $this->dao->update($oid, ['status' => '3']);
  1917. if (!$res) throw new ApiException(100007);
  1918. /** @var StoreOrderStatusServices $statusService */
  1919. $statusService = app()->make(StoreOrderStatusServices::class);
  1920. $statusService->save([
  1921. 'oid' => $oid,
  1922. 'change_type' => 'check_order_over',
  1923. 'change_message' => '用户评价',
  1924. 'change_time' => time()
  1925. ]);
  1926. $order = $this->dao->get((int)$oid, ['id,pid,status']);
  1927. if ($order && $order['pid'] > 0) {
  1928. $p_order = $this->dao->get((int)$order['pid'], ['id,pid,status']);
  1929. //主订单全部收货 且子订单没有待评价 有已完成
  1930. if ($p_order['status'] == 2 && !$this->dao->count(['pid' => $order['pid'], 'status' => 3]) && $this->dao->count(['pid' => $order['pid'], 'status' => 4])) {
  1931. $this->dao->update($p_order['id'], ['status' => 3]);
  1932. $statusService->save([
  1933. 'oid' => $p_order['id'],
  1934. 'change_type' => 'check_order_over',
  1935. 'change_message' => '用户评价',
  1936. 'change_time' => time()
  1937. ]);
  1938. }
  1939. }
  1940. }
  1941. }
  1942. /**
  1943. * 某个用户订单
  1944. * @param int $uid
  1945. * @param UserServices $userServices
  1946. * @return array
  1947. * @throws \think\db\exception\DataNotFoundException
  1948. * @throws \think\db\exception\DbException
  1949. * @throws \think\db\exception\ModelNotFoundException
  1950. */
  1951. public function getUserOrderList(int $uid)
  1952. {
  1953. /** @var UserServices $userServices */
  1954. $userServices = app()->make(UserServices::class);
  1955. $user = $userServices->getUserInfo($uid, 'uid');
  1956. if (!$user) {
  1957. throw new AdminException(100026);
  1958. }
  1959. [$page, $limit] = $this->getPageValue();
  1960. $where = ['uid' => $uid, 'paid' => 1, 'refund_status' => 0, 'pid' => 0];
  1961. $list = $this->dao->getStairOrderList($where, 'order_id,real_name,total_num,total_price,pay_price,FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time,paid,pay_type,pink_id,seckill_id,bargain_id', $page, $limit);
  1962. $count = $this->dao->count($where);
  1963. return compact('list', 'count');
  1964. }
  1965. /**
  1966. * 获取推广订单列表
  1967. * @param int $uid
  1968. * @param $where
  1969. * @return array
  1970. * @throws \think\db\exception\DataNotFoundException
  1971. * @throws \think\db\exception\DbException
  1972. * @throws \think\db\exception\ModelNotFoundException
  1973. */
  1974. public function getUserStairOrderList(int $uid, $where)
  1975. {
  1976. $where_data = [];
  1977. if (isset($where['type'])) {
  1978. switch ((int)$where['type']) {
  1979. case 1:
  1980. $where_data['spread_uid'] = $uid;
  1981. break;
  1982. case 2:
  1983. $where_data['spread_two_uid'] = $uid;
  1984. break;
  1985. case 3:
  1986. $where_data['division_id'] = $uid;
  1987. break;
  1988. case 4:
  1989. $where_data['agent_id'] = $uid;
  1990. break;
  1991. default:
  1992. $where_data['all_spread'] = $uid;
  1993. break;
  1994. }
  1995. }
  1996. if (isset($where['data']) && $where['data']) {
  1997. $where_data['time'] = $where['data'];
  1998. }
  1999. if (isset($where['order_id']) && $where['order_id']) {
  2000. $where_data['order_id'] = $where['order_id'];
  2001. }
  2002. //推广订单只显示支付过并且未退款的订单
  2003. $where_data['paid'] = 1;
  2004. $where_data['refund_status'] = 0;
  2005. [$page, $limit] = $this->getPageValue();
  2006. $list = $this->dao->getStairOrderList($where_data, '*', $page, $limit);
  2007. $count = $this->dao->count($where_data);
  2008. return compact('list', 'count');
  2009. }
  2010. /**
  2011. * 订单导出
  2012. * @param array $where
  2013. * @return array
  2014. * @throws \think\db\exception\DataNotFoundException
  2015. * @throws \think\db\exception\DbException
  2016. * @throws \think\db\exception\ModelNotFoundException
  2017. */
  2018. public function getExportList(array $where)
  2019. {
  2020. $list = $this->dao->search($where)->order('id desc')->select()->toArray();
  2021. foreach ($list as &$item) {
  2022. /** @var StoreOrderCartInfoServices $orderCart */
  2023. $orderCart = app()->make(StoreOrderCartInfoServices::class);
  2024. $_info = $orderCart->getCartColunm(['oid' => $item['id']], 'cart_info', 'unique');
  2025. foreach ($_info as $k => $v) {
  2026. $cart_info = is_string($v) ? json_decode($v, true) : $v;
  2027. if (!isset($cart_info['productInfo'])) $cart_info['productInfo'] = [];
  2028. $_info[$k] = $cart_info;
  2029. unset($cart_info);
  2030. }
  2031. $item['_info'] = $_info;
  2032. /** @var WechatUserServices $wechatUserService */
  2033. $wechatUserService = app()->make(WechatUserServices::class);
  2034. $item['sex'] = $wechatUserService->value(['uid' => $item['uid']], 'sex');
  2035. if ($item['pink_id'] || $item['combination_id']) {
  2036. /** @var StorePinkServices $pinkService */
  2037. $pinkService = app()->make(StorePinkServices::class);
  2038. $pinkStatus = $pinkService->value(['order_id_key' => $item['id']], 'status');
  2039. switch ($pinkStatus) {
  2040. case 1:
  2041. $item['pink_name'] = '[拼团订单]正在进行中';
  2042. $item['color'] = '#f00';
  2043. break;
  2044. case 2:
  2045. $item['pink_name'] = '[拼团订单]已完成';
  2046. $item['color'] = '#00f';
  2047. break;
  2048. case 3:
  2049. $item['pink_name'] = '[拼团订单]未完成';
  2050. $item['color'] = '#f0f';
  2051. break;
  2052. default:
  2053. $item['pink_name'] = '[拼团订单]历史订单';
  2054. $item['color'] = '#457856';
  2055. break;
  2056. }
  2057. } elseif ($item['seckill_id']) {
  2058. $item['pink_name'] = '[秒杀订单]';
  2059. $item['color'] = '#32c5e9';
  2060. } elseif ($item['bargain_id']) {
  2061. $item['pink_name'] = '[砍价订单]';
  2062. $item['color'] = '#12c5e9';
  2063. } else {
  2064. if ($item['shipping_type'] == 1) {
  2065. $item['pink_name'] = '[普通订单]';
  2066. $item['color'] = '#895612';
  2067. } else if ($item['shipping_type'] == 2) {
  2068. $item['pink_name'] = '[核销订单]';
  2069. $item['color'] = '#8956E8';
  2070. }
  2071. }
  2072. }
  2073. return $list;
  2074. }
  2075. /**
  2076. * 自动取消订单
  2077. * @return bool
  2078. * @throws \think\db\exception\DataNotFoundException
  2079. * @throws \think\db\exception\DbException
  2080. * @throws \think\db\exception\ModelNotFoundException
  2081. */
  2082. public function orderUnpaidCancel()
  2083. {
  2084. //系统预设取消订单时间段
  2085. $keyValue = ['order_cancel_time', 'order_activity_time', 'order_bargain_time', 'order_seckill_time', 'order_pink_time'];
  2086. //获取配置
  2087. $systemValue = SystemConfigService::more($keyValue);
  2088. //格式化数据
  2089. $systemValue = Arr::setValeTime($keyValue, is_array($systemValue) ? $systemValue : []);
  2090. $list = $this->dao->getOrderUnPaidList();
  2091. /** @var StoreOrderRefundServices $refundServices */
  2092. $refundServices = app()->make(StoreOrderRefundServices::class);
  2093. foreach ($list as $order) {
  2094. if ($order['pink_id'] || $order['combination_id']) {
  2095. $secs = $systemValue['order_pink_time'] ?: $systemValue['order_activity_time'];
  2096. } elseif ($order['seckill_id']) {
  2097. $secs = $systemValue['order_seckill_time'] ?: $systemValue['order_activity_time'];
  2098. } elseif ($order['bargain_id']) {
  2099. $secs = $systemValue['order_bargain_time'] ?: $systemValue['order_activity_time'];
  2100. } else {
  2101. $secs = $systemValue['order_cancel_time'];
  2102. }
  2103. if ($secs == 0) return true;
  2104. if (($order['add_time'] + bcmul($secs, '3600', 0)) < time()) {
  2105. try {
  2106. $this->transaction(function () use ($order, $refundServices) {
  2107. //回退积分和优惠卷
  2108. $res = $refundServices->integralAndCouponBack($order, 'cancel');
  2109. //回退库存和销量
  2110. $res = $res && $refundServices->regressionStock($order);
  2111. //修改订单状态
  2112. $res = $res && $this->dao->update($order['id'], ['is_del' => 1, 'mark' => '订单未支付已超过系统预设时间']);
  2113. if (!$res) {
  2114. Log::error('订单号' . $order['order_id'] . '自动取消订单失败');
  2115. }
  2116. return true;
  2117. });
  2118. /** @var StoreOrderCartInfoServices $cartServices */
  2119. $cartServices = app()->make(StoreOrderCartInfoServices::class);
  2120. $cartInfo = $cartServices->getOrderCartInfo((int)$order['id']);
  2121. } catch (\Throwable $e) {
  2122. Log::error('自动取消订单失败,失败原因:' . $e->getMessage(), $e->getTrace());
  2123. }
  2124. }
  2125. }
  2126. }
  2127. /**根据时间获取当天或昨天订单营业额
  2128. * @param array $where
  2129. * @return float|int
  2130. */
  2131. public function getOrderMoneyByWhere(array $where, string $sum_field, string $selectType, string $group = "")
  2132. {
  2133. switch ($selectType) {
  2134. case "sum" :
  2135. return $this->dao->getDayTotalMoney($where, $sum_field);
  2136. case "group" :
  2137. return $this->dao->getDayGroupMoney($where, $sum_field, $group);
  2138. }
  2139. }
  2140. /**统计时间段订单数
  2141. * @param array $where
  2142. * @param string $sum_field
  2143. */
  2144. public function getOrderCountByWhere(array $where)
  2145. {
  2146. return $this->dao->getDayOrderCount($where);
  2147. }
  2148. /**分组统计时间段订单数
  2149. * @param $where
  2150. * @return mixed
  2151. */
  2152. public function getOrderGroupCountByWhere($where)
  2153. {
  2154. return $this->dao->getOrderGroupCount($where);
  2155. }
  2156. /** 时间段支付订单人数
  2157. * @param $where
  2158. * @return mixed
  2159. */
  2160. public function getPayOrderPeopleByWhere($where)
  2161. {
  2162. return $this->dao->getPayOrderPeople($where);
  2163. }
  2164. /**时间段分组统计支付订单人数
  2165. * @param $where
  2166. * @return mixed
  2167. */
  2168. public function getPayOrderGroupPeopleByWhere($where)
  2169. {
  2170. return $this->dao->getPayOrderGroupPeople($where);
  2171. }
  2172. /**
  2173. * 退款订单列表
  2174. * @param array $where
  2175. * @return array
  2176. * @throws \think\db\exception\DataNotFoundException
  2177. * @throws \think\db\exception\DbException
  2178. * @throws \think\db\exception\ModelNotFoundException
  2179. */
  2180. public function refundList(array $where)
  2181. {
  2182. [$page, $limit] = $this->getPageValue();
  2183. if ($where['refund_reason_time'] != '') $where['refund_reason_time'] = explode('-', $where['refund_reason_time']);
  2184. $data = $this->dao->getRefundList($where, $page, $limit);
  2185. if ($data['list']) $data['list'] = $this->tidyOrderList($data['list']);
  2186. $data['num'] = [
  2187. 0 => ['name' => '全部', 'num' => $this->dao->count(['refund_type' => 0, 'is_system_del' => 0])],
  2188. 1 => ['name' => '仅退款', 'num' => $this->dao->count(['refund_type' => 1, 'is_system_del' => 0])],
  2189. 2 => ['name' => '退货退款', 'num' => $this->dao->count(['refund_type' => 2, 'is_system_del' => 0])],
  2190. 3 => ['name' => '拒绝退款', 'num' => $this->dao->count(['refund_type' => 3, 'is_system_del' => 0])],
  2191. 4 => ['name' => '商品待退货', 'num' => $this->dao->count(['refund_type' => 4, 'is_system_del' => 0])],
  2192. 5 => ['name' => '退货待收货', 'num' => $this->dao->count(['refund_type' => 5, 'is_system_del' => 0])],
  2193. 6 => ['name' => '已退款', 'num' => $this->dao->count(['refund_type' => 6, 'is_system_del' => 0])]
  2194. ];
  2195. return $data;
  2196. }
  2197. /**
  2198. * 商家同意退款,等待客户退货
  2199. * @param $order_id
  2200. * @return bool
  2201. */
  2202. public function agreeRefund($order_id)
  2203. {
  2204. $res = $this->dao->update(['id' => $order_id], ['refund_type' => 4]);
  2205. /** @var StoreOrderStatusServices $statusService */
  2206. $statusService = app()->make(StoreOrderStatusServices::class);
  2207. $statusService->save([
  2208. 'oid' => $order_id,
  2209. 'change_type' => 'refund_express',
  2210. 'change_message' => '等待用户退货',
  2211. 'change_time' => time()
  2212. ]);
  2213. if ($res) return true;
  2214. throw new AdminException(100005);
  2215. }
  2216. /**
  2217. * @param array $where
  2218. * @param array|string[] $field
  2219. * @param array $with
  2220. * @param int $page
  2221. * @param int $limit
  2222. * @param string $order
  2223. * @return array
  2224. * @throws \think\db\exception\DataNotFoundException
  2225. * @throws \think\db\exception\DbException
  2226. * @throws \think\db\exception\ModelNotFoundException
  2227. */
  2228. public function getSplitOrderList(array $where, array $field = ['*'], array $with = [], $page = 0, $limit = 0, $order = 'pay_time DESC,id DESC')
  2229. {
  2230. $data = $this->dao->getOrderList($where, $field, $page, $limit, $with, $order);
  2231. if ($data) {
  2232. $data = $this->tidyOrderList($data);
  2233. }
  2234. return $data;
  2235. }
  2236. /**
  2237. * 代付详情
  2238. * @param $orderId
  2239. * @param $uid
  2240. * @return array
  2241. * @throws \think\db\exception\DataNotFoundException
  2242. * @throws \think\db\exception\DbException
  2243. * @throws \think\db\exception\ModelNotFoundException
  2244. */
  2245. public function getFriendDetail($orderId, $uid)
  2246. {
  2247. $orderInfo = $this->dao->getOne(['id' => $orderId, 'is_del' => 0]);
  2248. if ($orderInfo) {
  2249. $orderInfo = $orderInfo->toArray();
  2250. } else {
  2251. throw new ApiException(410173);
  2252. }
  2253. $orderInfo = $this->tidyOrder($orderInfo, true);
  2254. /** @var UserServices $userServices */
  2255. $userServices = app()->make(UserServices::class);
  2256. $userInfo = $userServices->get($orderInfo['uid']);
  2257. $friendInfo = $userServices->get($orderInfo['pay_uid']);
  2258. $info = [
  2259. 'id' => $orderInfo['id'],
  2260. 'order_id' => $orderInfo['order_id'],
  2261. 'uid' => $orderInfo['uid'],
  2262. 'avatar' => $userInfo['avatar'],
  2263. 'nickname' => $userInfo['nickname'],
  2264. 'cartInfo' => $orderInfo['cartInfo'],
  2265. 'paid' => $orderInfo['paid'],
  2266. 'total_num' => $orderInfo['total_num'],
  2267. 'pay_price' => $orderInfo['pay_price'],
  2268. 'type' => $uid == $orderInfo['uid'] ? 0 : 1,
  2269. 'pay_uid' => isset($friendInfo) ? $friendInfo['uid'] : 0,
  2270. 'pay_nickname' => isset($friendInfo) ? $friendInfo['nickname'] : '',
  2271. 'pay_avatar' => isset($friendInfo) ? $friendInfo['avatar'] : '',
  2272. ];
  2273. return $info;
  2274. }
  2275. /**
  2276. * 获取退货商品列表
  2277. * @param array $cart_ids
  2278. * @param int $id
  2279. * @return array
  2280. * @throws \think\db\exception\DataNotFoundException
  2281. * @throws \think\db\exception\DbException
  2282. * @throws \think\db\exception\ModelNotFoundException
  2283. */
  2284. public function refundCartInfoList(array $cart_ids = [], int $id = 0)
  2285. {
  2286. $orderInfo = $this->dao->get($id);
  2287. if (!$orderInfo) {
  2288. throw new ApiException(410173);
  2289. }
  2290. $orderInfo = $this->tidyOrder($orderInfo, true);
  2291. $cartInfo = $orderInfo['cartInfo'] ?? [];
  2292. $data = [];
  2293. if ($cart_ids) {
  2294. foreach ($cart_ids as $cart) {
  2295. if (!isset($cart['cart_id']) || !$cart['cart_id'] || !isset($cart['cart_num']) || !$cart['cart_num'] || $cart['cart_num'] <= 0) {
  2296. throw new ApiException(410223);
  2297. }
  2298. }
  2299. $cart_ids = array_combine(array_column($cart_ids, 'cart_id'), $cart_ids);
  2300. $i = 0;
  2301. foreach ($cartInfo as $item) {
  2302. if (isset($cart_ids[$item['id']])) {
  2303. $data['cartInfo'][$i] = $item;
  2304. if (isset($cart_ids[$item['id']]['cart_num'])) $data['cartInfo'][$i]['cart_num'] = $cart_ids[$item['id']]['cart_num'];
  2305. $i++;
  2306. }
  2307. }
  2308. }
  2309. $data['_status'] = $orderInfo['_status'] ?? [];
  2310. $data['_status']['_is_back'] = $orderInfo['delivery_type'] != 'fictitious' && $orderInfo['virtual_type'] == 0;
  2311. $data['cartInfo'] = $data['cartInfo'] ?? $cartInfo;
  2312. return $data;
  2313. }
  2314. /**
  2315. * 再次下单
  2316. * @param string $uni
  2317. * @param int $uid
  2318. * @return array
  2319. */
  2320. public function againOrder(StoreCartServices $services, string $uni, int $uid): array
  2321. {
  2322. if (!$uni) throw new ApiException(100100);
  2323. $order = $this->getUserOrderDetail($uni, $uid);
  2324. if (!$order) throw new ApiException(410173);
  2325. $order = $this->tidyOrder($order, true);
  2326. $cateId = [];
  2327. foreach ($order['cartInfo'] as $v) {
  2328. if ($v['combination_id']) throw new ApiException(410258);
  2329. elseif ($v['bargain_id']) throw new ApiException(410259);
  2330. elseif ($v['seckill_id']) throw new ApiException(410260);
  2331. elseif ($v['advance_id']) throw new ApiException(410261);
  2332. else $cateId[] = $services->setCart($uid, (int)$v['product_id'], (int)$v['cart_num'], $v['productInfo']['attrInfo']['unique'] ?? '', '0', true);
  2333. }
  2334. if (!$cateId) throw new ApiException(410262);
  2335. return $cateId;
  2336. }
  2337. /**
  2338. * 支付宝单独支付
  2339. * @param OrderPayServices $payServices
  2340. * @param OtherOrderServices $services
  2341. * @param string $key
  2342. * @param string $quitUrl
  2343. * @return array|string
  2344. * @throws \think\db\exception\DataNotFoundException
  2345. * @throws \think\db\exception\DbException
  2346. * @throws \think\db\exception\ModelNotFoundException
  2347. */
  2348. public function aliPayOrder(OrderPayServices $payServices, OtherOrderServices $services, string $key, string $quitUrl)
  2349. {
  2350. if (!$key) {
  2351. throw new ApiException(100100);
  2352. }
  2353. if (!$quitUrl) {
  2354. throw new ApiException(100100);
  2355. }
  2356. $orderCache = CacheService::get($key);
  2357. if (!$orderCache || !isset($orderCache['order_id'])) {
  2358. throw new ApiException(410263);
  2359. }
  2360. $payType = isset($orderCache['other_pay_type']) && $orderCache['other_pay_type'] == true;
  2361. if ($payType) {
  2362. $orderInfo = $services->getOne(['order_id' => $orderCache['order_id'], 'is_del' => 0, 'paid' => 0]);
  2363. } else {
  2364. $orderInfo = $this->get(['order_id' => $orderCache['order_id'], 'paid' => 0, 'is_del' => 0]);
  2365. }
  2366. if (!$orderInfo) {
  2367. throw new ApiException(410264);
  2368. }
  2369. return $payServices->beforePay($orderInfo->toArray(), PayServices::ALIAPY_PAY, ['quitUrl' => $quitUrl]);
  2370. }
  2371. /**
  2372. * 用户订单信息
  2373. * @param StoreOrderEconomizeServices $services
  2374. * @param string $uni
  2375. * @param int $uid
  2376. * @return void
  2377. * @throws \think\db\exception\DataNotFoundException
  2378. * @throws \think\db\exception\DbException
  2379. * @throws \think\db\exception\ModelNotFoundException
  2380. */
  2381. public function getUserOrderByKey(StoreOrderEconomizeServices $services, string $uni, int $uid): array
  2382. {
  2383. $order = $this->getUserOrderDetail($uni, $uid, ['split', 'invoice']);
  2384. if (!$order) throw new ApiException(410294);
  2385. $order = $order->toArray();
  2386. $splitNum = [];
  2387. //是否开启门店自提
  2388. $store_self_mention = sys_config('store_self_mention');
  2389. //关闭门店自提后 订单隐藏门店信息
  2390. if ($store_self_mention == 0) $order['shipping_type'] = 1;
  2391. if ($order['verify_code']) {
  2392. $verify_code = $order['verify_code'];
  2393. $verify[] = substr($verify_code, 0, 4);
  2394. $verify[] = substr($verify_code, 4, 4);
  2395. $verify[] = substr($verify_code, 8);
  2396. $order['_verify_code'] = implode(' ', $verify);
  2397. }
  2398. $order['add_time_y'] = date('Y-m-d', $order['add_time']);
  2399. $order['add_time_h'] = date('H:i:s', $order['add_time']);
  2400. $order['system_store'] = false;
  2401. if ($order['store_id']) {
  2402. /** @var SystemStoreServices $storeServices */
  2403. $storeServices = app()->make(SystemStoreServices::class);
  2404. $order['system_store'] = $storeServices->getStoreDispose($order['store_id']);
  2405. }
  2406. $order['code'] = '';
  2407. if (($order['shipping_type'] === 2 || $order['delivery_uid'] != 0) && $order['verify_code']) {
  2408. // $name = $order['verify_code'] . '.jpg';
  2409. // /** @var SystemAttachmentServices $attachmentServices */
  2410. // $attachmentServices = app()->make(SystemAttachmentServices::class);
  2411. // $imageInfo = $attachmentServices->getInfo(['name' => $name]);
  2412. // $siteUrl = sys_config('site_url');
  2413. // if (!$imageInfo) {
  2414. // $imageInfo = PosterServices::getQRCodePath($order['verify_code'], $name);
  2415. // if (is_array($imageInfo)) {
  2416. // $attachmentServices->attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2);
  2417. // $url = $imageInfo['dir'];
  2418. // } else
  2419. // $url = '';
  2420. // } else $url = $imageInfo['att_dir'];
  2421. // if (isset($imageInfo['image_type']) && $imageInfo['image_type'] == 1) $url = $siteUrl . $url;
  2422. // $order['code'] = $url;
  2423. try {
  2424. $verifyName = 'verify_code_' . $order['verify_code'] . '.jpg';
  2425. $data = 'verify_code=' . $order['verify_code'];
  2426. /** @var SystemAttachmentServices $systemAttachmentService */
  2427. $systemAttachmentService = app()->make(SystemAttachmentServices::class);
  2428. $imageInfo = $systemAttachmentService->getOne(['name' => $verifyName]);
  2429. $siteUrl = sys_config('site_url');
  2430. if (!$imageInfo) {
  2431. $res = MiniProgramService::appCodeUnlimitService($data, 'pages/admin/order_cancellation/index', 280);
  2432. if (!$res) throw new ApiException('小程序核销码生成失败');
  2433. $uploadType = (int)sys_config('upload_type', 1);
  2434. $upload = UploadService::init();
  2435. $res = (string)EntityBody::factory($res);
  2436. $res = $upload->to('routine/product')->validate()->setAuthThumb(false)->stream($res, $verifyName);
  2437. if ($res === false) throw new ApiException('小程序核销码生成失败');
  2438. $imageInfo = $upload->getUploadInfo();
  2439. $imageInfo['image_type'] = $uploadType;
  2440. if ($imageInfo['image_type'] == 1) $remoteImage = PosterServices::remoteImage($siteUrl . $imageInfo['dir']);
  2441. else $remoteImage = PosterServices::remoteImage($imageInfo['dir']);
  2442. if (!$remoteImage['status']) throw new ApiException('小程序核销码生成失败');
  2443. $systemAttachmentService->save([
  2444. 'name' => $imageInfo['name'],
  2445. 'att_dir' => $imageInfo['dir'],
  2446. 'satt_dir' => $imageInfo['thumb_path'],
  2447. 'att_size' => $imageInfo['size'],
  2448. 'att_type' => $imageInfo['type'],
  2449. 'image_type' => $imageInfo['image_type'],
  2450. 'module_type' => 2,
  2451. 'time' => time(),
  2452. 'pid' => 1,
  2453. 'type' => 2
  2454. ]);
  2455. $url = $imageInfo['dir'];
  2456. } else $url = $imageInfo['att_dir'];
  2457. if ($imageInfo['image_type'] == 1) $url = $siteUrl . $url;
  2458. $order['code'] = $url;
  2459. } catch (\Exception $e) {
  2460. }
  2461. }
  2462. $order['mapKey'] = sys_config('tengxun_map_key');
  2463. $order['yue_pay_status'] = (int)sys_config('balance_func_status') && (int)sys_config('yue_pay_status') == 1 ? (int)1 : (int)2;//余额支付 1 开启 2 关闭
  2464. $order['pay_weixin_open'] = sys_config('pay_weixin_open') != '0';//微信支付 1 开启 0 关闭
  2465. $order['ali_pay_status'] = sys_config('ali_pay_status', '0') != '0';//支付包支付 1 开启 0 关闭
  2466. $order['friend_pay_status'] = (int)sys_config('friend_pay_status') ?? 0;//好友代付 1 开启 0 关闭
  2467. $orderData = $this->tidyOrder($order, true, true);
  2468. $vipTruePrice = $memberPrice = $levelPrice = 0;
  2469. foreach ($orderData['cartInfo'] ?? [] as $key => $cart) {
  2470. $vipTruePrice = bcadd((string)$vipTruePrice, (string)$cart['vip_sum_truePrice'], 2);
  2471. if ($cart['price_type'] == 'member') $memberPrice = bcadd((string)$memberPrice, (string)$cart['vip_sum_truePrice'], 2);
  2472. if ($cart['price_type'] == 'level') $levelPrice = bcadd((string)$levelPrice, (string)$cart['vip_sum_truePrice'], 2);
  2473. if (isset($splitNum[$cart['id']])) {
  2474. $orderData['cartInfo'][$key]['cart_num'] = $cart['cart_num'] - $splitNum[$cart['id']];
  2475. if ($orderData['cartInfo'][$key]['cart_num'] == 0) unset($orderData['cartInfo'][$key]);
  2476. }
  2477. }
  2478. $orderData['cartInfo'] = array_merge($orderData['cartInfo']);
  2479. $orderData['vip_true_price'] = $vipTruePrice;
  2480. $orderData['levelPrice'] = $levelPrice;
  2481. $orderData['memberPrice'] = $memberPrice;
  2482. $economize = $services->get(['order_id' => $order['order_id']], ['postage_price', 'member_price']);
  2483. if ($economize) {
  2484. $orderData['postage_price'] = $economize['postage_price'];
  2485. $orderData['member_price'] = $economize['member_price'];
  2486. } else {
  2487. $orderData['postage_price'] = 0;
  2488. $orderData['member_price'] = 0;
  2489. }
  2490. $orderData['routine_contact_type'] = sys_config('routine_contact_type', 0);
  2491. /** @var UserInvoiceServices $userInvoice */
  2492. $userInvoice = app()->make(UserInvoiceServices::class);
  2493. $invoice_func = $userInvoice->invoiceFuncStatus();
  2494. $orderData['invoice_func'] = $invoice_func['invoice_func'];
  2495. $orderData['special_invoice'] = $invoice_func['special_invoice'];
  2496. $orderData['refund_cartInfo'] = $orderData['cartInfo'];
  2497. $orderData['refund_total_num'] = $orderData['total_num'];
  2498. $orderData['refund_pay_price'] = $orderData['pay_price'];
  2499. $orderData['is_apply_refund'] = true;
  2500. $orderData['help_info'] = [
  2501. 'pay_uid' => $orderData['pay_uid'],
  2502. 'pay_nickname' => '',
  2503. 'pay_avatar' => '',
  2504. 'help_status' => 0
  2505. ];
  2506. if ($orderData['uid'] != $orderData['pay_uid']) {
  2507. /** @var UserServices $userServices */
  2508. $userServices = app()->make(UserServices::class);
  2509. $payUser = $userServices->get($orderData['pay_uid'], ['nickname', 'avatar']);
  2510. $orderData['help_info'] = [
  2511. 'pay_uid' => $orderData['pay_uid'],
  2512. 'pay_nickname' => $payUser['nickname'],
  2513. 'pay_avatar' => $payUser['avatar'],
  2514. 'help_status' => 1
  2515. ];
  2516. }
  2517. // 判断是否开启小程序订单管理
  2518. $orderData['order_shipping_open'] = false;
  2519. if (sys_config('order_shipping_open', 0) && $order['pay_price'] > 0 && $order['is_channel'] == 1 && $order['pay_type'] == 'weixin' && MiniOrderService::isManaged()) {
  2520. // 判断是否存在子未收货子订单
  2521. if ($order['pid'] > 0) {
  2522. if ($this->checkSubOrderNotTake((int)$order['pid'], (int)$order['id'])) {
  2523. $orderData['order_shipping_open'] = true;
  2524. }
  2525. } else {
  2526. $orderData['order_shipping_open'] = true;
  2527. }
  2528. }
  2529. $orderData['is_refund_available'] = $this->isRefundAvailable((int)$order['id']);
  2530. return $orderData;
  2531. }
  2532. /**
  2533. * 检测订单是否能退款
  2534. * @param $oid
  2535. * @return bool
  2536. * @author: 吴汐
  2537. * @email: 442384644@qq.com
  2538. * @date: 2023/10/11
  2539. */
  2540. public function isRefundAvailable($oid)
  2541. {
  2542. $refundTimeAvailable = (int)sys_config('refund_time_available');
  2543. if ($refundTimeAvailable == 0) return true;
  2544. $statusInfo = app()->make(StoreOrderStatusServices::class)->get(['oid' => $oid, 'change_type' => 'take_delivery']);
  2545. if (!$statusInfo) return true;
  2546. $changeTime = preg_match('/^\d+$/', $statusInfo['change_time']) ? intval($statusInfo['change_time']) : strtotime($statusInfo['change_time']);
  2547. if (($changeTime + ($refundTimeAvailable * 86400)) < time()) {
  2548. return false;
  2549. }
  2550. return true;
  2551. }
  2552. /**
  2553. * 获取确认订单页面是否展示快递配送和到店自提
  2554. * @param $uid
  2555. * @param $cartIds
  2556. * @param $new
  2557. * @return array
  2558. * @throws \Psr\SimpleCache\InvalidArgumentException
  2559. */
  2560. public function checkShipping($uid, $cartIds, $new)
  2561. {
  2562. if ($new) {
  2563. $cartIds = explode(',', $cartIds);
  2564. $cartInfo = [];
  2565. foreach ($cartIds as $key) {
  2566. $info = CacheService::get($key);
  2567. if ($info) {
  2568. $cartInfo[] = $info;
  2569. }
  2570. }
  2571. } else {
  2572. /** @var StoreCartServices $cartServices */
  2573. $cartServices = app()->make(StoreCartServices::class);
  2574. $cartInfo = $cartServices->getCartList(['uid' => $uid, 'status' => 1, 'id' => $cartIds], 0, 0, ['productInfo', 'attrInfo']);
  2575. }
  2576. if (!$cartInfo) {
  2577. throw new ApiException(100026);
  2578. }
  2579. $arr = [];
  2580. foreach ($cartInfo as $item) {
  2581. $arr[] = $item['productInfo']['logistics'];
  2582. }
  2583. $res = array_unique(explode(',', implode(',', $arr)));
  2584. if (count($res) == 2) {
  2585. return ['type' => 0];
  2586. } else {
  2587. if ($res[0] == 2 && sys_config('store_self_mention') == 0) {
  2588. return ['type' => 1];
  2589. }
  2590. return ['type' => (int)$res[0]];
  2591. }
  2592. }
  2593. /**
  2594. * 自动评价
  2595. * @return bool
  2596. */
  2597. public function autoComment()
  2598. {
  2599. //自动评价天数
  2600. $systemCommentTime = sys_config('system_comment_time', 0);
  2601. //0为取消自动默认好评功能
  2602. if ($systemCommentTime == 0) {
  2603. return true;
  2604. }
  2605. $sevenDay = bcsub((string)time(), bcmul((string)$systemCommentTime, '86400'));
  2606. /** @var StoreOrderStoreOrderStatusServices $service */
  2607. $service = app()->make(StoreOrderStoreOrderStatusServices::class);
  2608. $orderList = $service->getTakeOrderIds([
  2609. 'change_time' => $sevenDay,
  2610. 'is_del' => 0,
  2611. 'paid' => 1,
  2612. 'status' => 2,
  2613. 'change_type' => ['take_delivery', 'user_take_delivery']
  2614. ], 30);
  2615. foreach ($orderList as $item) {
  2616. AutoCommentJob::dispatch([$item['id'], $item['cart_id']]);
  2617. }
  2618. return true;
  2619. }
  2620. /**
  2621. * @param int $uid
  2622. * @param string $orderId
  2623. * @param string $type
  2624. * @return array
  2625. * @throws \think\db\exception\DataNotFoundException
  2626. * @throws \think\db\exception\DbException
  2627. * @throws \think\db\exception\ModelNotFoundException
  2628. * @author 等风来
  2629. * @email 136327134@qq.com
  2630. * @date 2023/2/13
  2631. */
  2632. public function getCashierInfo(int $uid, string $orderId, string $type)
  2633. {
  2634. //支付类型开关
  2635. $data = [
  2636. 'ali_pay_status' => sys_config('ali_pay_status', '0') != '0',
  2637. 'wechat_pay_status' => sys_config('pay_weixin_open', '0') != '0',
  2638. 'offline_pay_status' => (int)sys_config('offline_pay_status') == 1,
  2639. 'friend_pay_status' => (int)sys_config('friend_pay_status') == 1,
  2640. 'yue_pay_status' => (int)sys_config('balance_func_status') && (int)sys_config('yue_pay_status') == 1,
  2641. ];
  2642. $data['order_id'] = $orderId;
  2643. $data['pay_price'] = '0';
  2644. $data['now_money'] = app()->make(UserServices::class)->value(['uid' => $uid], 'now_money');
  2645. switch ($type) {
  2646. case 'order':
  2647. $info = $this->dao->get(['order_id' => $orderId], ['id', 'pay_price', 'add_time', 'combination_id', 'seckill_id', 'bargain_id', 'pay_postage']);
  2648. if (!$info) {
  2649. throw new PayException('您支付的订单不存在');
  2650. }
  2651. $orderCancelTime = sys_config('order_cancel_time', 0);
  2652. $orderActivityTime = sys_config('order_activity_time', 0);
  2653. if ($info->combination_id) {
  2654. $time = (sys_config('order_pink_time', 0) ?: $orderActivityTime) * 60 * 60 + ((int)$info->add_time);
  2655. } else if ($info->seckill_id) {
  2656. $time = (sys_config('order_seckill_time', 0) ?: $orderActivityTime) * 60 * 60 + ((int)$info->add_time);
  2657. } else if ($info->bargain_id) {
  2658. $time = (sys_config('order_bargain_time', 0) ?: $orderActivityTime) * 60 * 60 + ((int)$info->add_time);
  2659. } else {
  2660. $time = $orderCancelTime * 60 * 60 + ((int)$info->add_time);
  2661. }
  2662. if ($time < 0) {
  2663. $time = 0;
  2664. }
  2665. $data['pay_price'] = $info['pay_price'];
  2666. $data['pay_postage'] = $info['pay_postage'];
  2667. $data['offline_postage'] = (int)sys_config('offline_postage', 0);
  2668. $data['invalid_time'] = $time;
  2669. $data['oid'] = $info['id'];
  2670. break;
  2671. case 'svip':
  2672. $info = app()->make(OtherOrderServices::class)->get(['order_id' => $orderId], ['id', 'pay_price', 'add_time']);
  2673. if (!$info) {
  2674. throw new PayException('您支付的订单不存在');
  2675. }
  2676. $data['pay_price'] = $info['pay_price'];
  2677. $data['invalid_time'] = $info->add_time + 86400;
  2678. break;
  2679. case 'recharge':
  2680. $info = app()->make(UserRechargeServices::class)->get(['order_id' => $orderId], ['id', 'price', 'add_time']);
  2681. if (!$info) {
  2682. throw new PayException('您支付的订单不存在');
  2683. }
  2684. $data['pay_price'] = $info['price'];
  2685. $data['invalid_time'] = $info->add_time + 86400;
  2686. break;
  2687. default:
  2688. throw new PayException('暂不支持其他类型订单支付');
  2689. }
  2690. return $data;
  2691. }
  2692. /**
  2693. * 取消商家寄件
  2694. * @param int $id
  2695. * @param string $msg
  2696. * @return array|mixed
  2697. * @throws \think\db\exception\DataNotFoundException
  2698. * @throws \think\db\exception\DbException
  2699. * @throws \think\db\exception\ModelNotFoundException
  2700. * @author 等风来
  2701. * @email 136327134@qq.com
  2702. * @date 2023/5/15
  2703. */
  2704. public function shipmentCancelOrder(int $id, string $msg)
  2705. {
  2706. $orderInfo = $this->dao->get($id);
  2707. if (!$orderInfo) {
  2708. throw new AdminException('取消的订单不存在');
  2709. }
  2710. if (!$orderInfo->kuaidi_task_id || !$orderInfo->kuaidi_order_id) {
  2711. throw new AdminException('商家寄件订单信息不存在,无法取消');
  2712. }
  2713. if ($orderInfo->is_stock_up != 1) {
  2714. throw new AdminException('订单状态不正确,无法取消寄件');
  2715. }
  2716. //发起取消商家寄件
  2717. app()->make(ServeServices::class)->express()->shipmentCancelOrder([
  2718. 'task_id' => $orderInfo->kuaidi_task_id,
  2719. 'order_id' => $orderInfo->kuaidi_order_id,
  2720. 'cancel_msg' => $msg,
  2721. ]);
  2722. //订单返回原状态
  2723. $this->transaction(function () use ($id, $msg, $orderInfo) {
  2724. app()->make(StoreOrderStatusServices::class)->save([
  2725. 'oid' => $id,
  2726. 'change_time' => time(),
  2727. 'change_type' => 'delivery_goods_cancel',
  2728. 'change_message' => '已取消发货,取消原因:' . $msg
  2729. ]);
  2730. $orderInfo->status = 0;
  2731. $orderInfo->is_stock_up = 0;
  2732. $orderInfo->kuaidi_task_id = '';
  2733. $orderInfo->kuaidi_order_id = '';
  2734. $orderInfo->express_dump = '';
  2735. $orderInfo->kuaidi_label = '';
  2736. $orderInfo->delivery_id = '';
  2737. $orderInfo->delivery_code = '';
  2738. $orderInfo->delivery_name = '';
  2739. $orderInfo->delivery_type = '';
  2740. $orderInfo->save();
  2741. });
  2742. return true;
  2743. }
  2744. /**
  2745. * 判断订单是否全部发货
  2746. * @param int $pid
  2747. * @param int $order_id
  2748. * @return bool
  2749. * @author: 吴汐
  2750. * @email: 442384644@qq.com
  2751. * @date: 2023/8/31
  2752. */
  2753. public function checkSubOrderNotSend(int $pid, int $order_id)
  2754. {
  2755. $order_count = $this->dao->getSubOrderNotSend($pid, $order_id);
  2756. if ($order_count > 0) {
  2757. return false;
  2758. } else {
  2759. return true;
  2760. }
  2761. }
  2762. /**
  2763. * 判断是否存在子未收货子订单
  2764. * @param int $pid
  2765. * @param int $order_id
  2766. * @return bool
  2767. * @author: 吴汐
  2768. * @email: 442384644@qq.com
  2769. * @date: 2023/8/31
  2770. */
  2771. public function checkSubOrderNotTake(int $pid, int $order_id)
  2772. {
  2773. $order_count = $this->dao->getSubOrderNotTake($pid, $order_id);
  2774. if ($order_count > 0) {
  2775. return false;
  2776. } else {
  2777. return true;
  2778. }
  2779. }
  2780. /**
  2781. * 配货单数据
  2782. * @param $oid
  2783. * @return array
  2784. * @throws \think\db\exception\DataNotFoundException
  2785. * @throws \think\db\exception\DbException
  2786. * @throws \think\db\exception\ModelNotFoundException
  2787. * @author: 吴汐
  2788. * @email: 442384644@qq.com
  2789. * @date: 2023/10/11
  2790. */
  2791. public function printShippingData($order_id)
  2792. {
  2793. $orderInfo = $this->dao->get(['order_id' => $order_id]);
  2794. if (!$orderInfo) {
  2795. throw new AdminException('订单不存在');
  2796. }
  2797. $orderInfo = $this->tidyOrder($orderInfo->toArray(), true);
  2798. $data['user_name'] = $orderInfo['real_name'];
  2799. $data['user_phone'] = $orderInfo['user_phone'];
  2800. $data['user_address'] = $orderInfo['user_address'];
  2801. $data['order_id'] = $orderInfo['order_id'];
  2802. $data['pay_time'] = $orderInfo['_pay_time'];
  2803. $data['pay_type'] = $orderInfo['_status']['_payType'];
  2804. $data['pay_price'] = $orderInfo['pay_price'];
  2805. $data['pay_postage'] = $orderInfo['pay_postage'];
  2806. $data['deduction_price'] = $orderInfo['deduction_price'];
  2807. $data['coupon_price'] = $orderInfo['coupon_price'];
  2808. $data['mark'] = $orderInfo['mark'];
  2809. $data['product_info'] = [];
  2810. $data['vip_price'] = 0;
  2811. foreach ($orderInfo['cartInfo'] as $item) {
  2812. $data['product_info'][] = [
  2813. 'name' => $item['productInfo']['store_name'],
  2814. 'sku' => $item['attrInfo']['suk'],
  2815. 'price' => $item['sum_price'],
  2816. 'num' => $item['cart_num'],
  2817. 'sum_price' => bcmul((string)$item['sum_price'], (string)$item['cart_num'], 2)
  2818. ];
  2819. $data['vip_price'] = bcadd((string)$data['vip_price'], $item['vip_sum_truePrice'], 2);
  2820. }
  2821. return $data;
  2822. }
  2823. }