StoreOrder.php 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\model\order;
  12. use app\admin\model\user\User;
  13. use app\admin\model\user\UserBill;
  14. use app\admin\model\wechat\WechatUser;
  15. use app\admin\model\ump\StorePink;
  16. use app\admin\model\store\StoreProduct;
  17. use service\PHPExcelService;
  18. use traits\ModelTrait;
  19. use basic\ModelBasic;
  20. use service\WechatTemplateService;
  21. use think\Url;
  22. use think\Db;
  23. use service\SystemConfigService;
  24. /**
  25. * 订单管理Model
  26. * Class StoreOrder
  27. * @package app\admin\model\store
  28. */
  29. class StoreOrder extends ModelBasic
  30. {
  31. use ModelTrait;
  32. public static function getOrderList($where)
  33. {
  34. $model = UserBill::where('u.uid', $where['uid'])->alias('u')->join('__STORE_ORDER__ a', 'a.id=u.link_id')
  35. ->where('u.category', 'now_money')->where('u.type', 'in', ['rake_back', 'rake_back_one'])
  36. ->where(['a.paid' => 1, 'a.is_gift' => 0, 'a.is_receive_gift' => 0])->order('a.add_time desc')->field('a.*');
  37. if ($where['start_date'] && $where['end_date']) $model = $model->where('a.add_time', 'between', [strtotime($where['start_date']), strtotime($where['end_date'])]);
  38. if ($where['excel']) {
  39. $list = $model->select();
  40. $excel = [];
  41. foreach ($list as $item) {
  42. $item['title'] = self::getDb('special')->where('id', $item['cart_id'])->value('title');
  43. $item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
  44. $item['nickname'] = self::getDb('user')->where('uid', $item['uid'])->value('nickname');
  45. $excel[] = [$item['add_time'], $item['order_id'], $item['nickname'], $item['title'], $item['pay_price'],];
  46. }
  47. PHPExcelService::setExcelHeader(['时间', '订单号', '用户名', '商品名', '订单金额'])
  48. ->setExcelTile('直推订单导出', '直推订单信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
  49. ->setExcelContent($excel)->ExcelSave();
  50. } else
  51. $list = $model->page((int)$where['page'], (int)$where['limit'])->select();
  52. $list = count($list)>0 ? $list->toArray() : [];
  53. foreach ($list as &$item) {
  54. $item['title'] = self::getDb('special')->where('id', $item['cart_id'])->value('title');
  55. $item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
  56. $item['nickname'] = self::getDb('user')->where('uid', $item['uid'])->value('nickname');
  57. }
  58. return $list;
  59. }
  60. public static function orderCount($type=0)
  61. {
  62. $data['wz'] = self::statusByWhere(0, new self(),'',$type)->count();
  63. $data['wf'] = self::statusByWhere(1, new self(),'',$type)->count();
  64. $data['sh'] = self::statusByWhere(2, new self(),'',$type)->count();
  65. $data['wc'] = self::statusByWhere(3, new self(),'',$type)->count();
  66. $data['pt'] = self::statusByWhere(5, new self(),'',$type)->count();
  67. $data['pu'] = self::statusByWhere(6, new self(),'',$type)->count();
  68. $data['lw'] = self::statusByWhere(7, new self(),'',$type)->count();
  69. $data['sp'] = self::statusByWhere(8, new self(),'',$type)->count();
  70. $data['vip'] = self::statusByWhere(9, new self(),'',$type)->count();
  71. $data['tk'] = self::statusByWhere(-1, new self(),'',$type)->count();
  72. $data['yt'] = self::statusByWhere(-2, new self(),'',$type)->count();
  73. return $data;
  74. }
  75. public static function OrderList($where)
  76. {
  77. $model = self::getOrderWhere($where, self::alias('a')->join('user r', 'r.uid=a.uid', 'LEFT'), 'a.', 'r')->field('a.*,r.nickname,r.phone');
  78. if ($where['order'] != '') {
  79. $model = $model->order(self::setOrder($where['order']));
  80. } else {
  81. $model = $model->order('a.id desc');
  82. }
  83. if (isset($where['mer_id']) && $where['mer_id']) $model->where('mer_id', $where['mer_id']);
  84. if (isset($where['excel']) && $where['excel'] == 1) {
  85. $data = ($data = $model->select()) && count($data) ? $data->toArray() : [];
  86. } else {
  87. $data = ($data = $model->page((int)$where['page'], (int)$where['limit'])->select()) && count($data) ? $data->toArray() : [];
  88. }
  89. foreach ($data as &$item) {
  90. switch ($item['type']){
  91. case 0:
  92. $item['_info'] = db('special')->where('id', $item['cart_id'])->find();
  93. if ($item['pink_id']) {
  94. $item['pink_name'] = '[拼团订单]';
  95. $item['color'] = '#895612';
  96. } else if ($item['is_gift'] && !$item['pink_id']) {
  97. $item['pink_name'] = '[送礼物订单]';
  98. $item['color'] = '#895612';
  99. } else if (!$item['is_gift'] && !$item['pink_id'] && $item['gift_order_id']) {
  100. $item['pink_name'] = '[领礼物订单]';
  101. $item['color'] = '#895612';
  102. } else {
  103. $item['pink_name'] = '[普通订单]';
  104. $item['color'] = '#895612';
  105. }
  106. if (!$item['_info']){
  107. $item['_info']['title'] = '专题被删除';
  108. }else{
  109. $len=strlen($item['_info']['title']);
  110. $item['_info']['title'] =$len > 16 ? mb_substr($item['_info']['title'],0,16).'...' : $item['_info']['title'];
  111. }
  112. break;
  113. case 1:
  114. $item['_info'] = db('member_ship')->where('id', $item['member_id'])->find();
  115. $item['pink_name'] = '[会员订单]';
  116. $item['color'] = '#895612';
  117. if (!$item['_info']) $item['_info']['title'] = '会员被删除';
  118. break;
  119. case 2:
  120. $_info = Db::name('store_order_cart_info')->where('oid', $item['id'])->field('cart_info')->select();
  121. foreach ($_info as $k => $v) {
  122. $cart_info = json_decode($v['cart_info'], true);
  123. if (!isset($cart_info['productInfo'])) $cart_info['productInfo'] = [];
  124. $len=strlen($cart_info['productInfo']['store_name']);
  125. $cart_info['productInfo']['store_name']=$len > 30 ? mb_substr($cart_info['productInfo']['store_name'],0,30).'...' : $cart_info['productInfo']['store_name'];
  126. $_info[$k]['cart_info'] = $cart_info;
  127. unset($cart_info);
  128. }
  129. $item['_info'] = $_info;
  130. $item['pink_name'] = '[商品订单]';
  131. $item['color'] = '#895612';
  132. break;
  133. }
  134. if ($item['paid'] == 1) {
  135. switch ($item['pay_type']) {
  136. case 'weixin':
  137. $item['pay_type_name'] = '微信支付';
  138. break;
  139. case 'yue':
  140. $item['pay_type_name'] = '余额支付';
  141. break;
  142. case 'offline':
  143. $item['pay_type_name'] = '线下支付';
  144. break;
  145. case 'zhifubao':
  146. $item['pay_type_name'] = '支付宝支付';
  147. break;
  148. default:
  149. $item['pay_type_name'] = '其他支付';
  150. break;
  151. }
  152. } else {
  153. switch ($item['pay_type']) {
  154. case 'offline':
  155. $item['pay_type_name'] = '线下支付';
  156. $item['pay_type_info'] = 1;
  157. break;
  158. default:
  159. $item['pay_type_name'] = '未支付';
  160. break;
  161. }
  162. }
  163. if ($item['paid'] == 0 && $item['status'] == 0) {
  164. $item['status_name'] = '未支付';
  165. } else if ($item['paid'] == 1 && $item['status'] == 0 && $item['refund_status'] == 0 && $item['type'] != 2) {
  166. $item['status_name'] = '已支付';
  167. } else if ($item['paid'] == 1 && $item['status'] == 0 && $item['refund_status'] == 0 && $item['type'] == 2) {
  168. $item['status_name'] = '待发货';
  169. } else if ($item['paid'] == 1 && $item['status'] == 1 && $item['refund_status'] == 0 && $item['type'] == 2) {
  170. $item['status_name'] = '待收货';
  171. } else if ($item['paid'] == 1 && $item['status'] == 2 && $item['refund_status'] == 0 && $item['type'] == 2) {
  172. $item['status_name'] = '已完成';
  173. } else if ($item['paid'] == 1 && $item['refund_status'] == 1) {
  174. $item['status_name'] = <<<HTML
  175. <b style="color:#f124c7">申请退款</b><br/>
  176. HTML;
  177. } else if ($item['paid'] == 1 && $item['refund_status'] == 2) {
  178. $item['status_name'] = '已退款';
  179. }
  180. if ($item['paid'] == 0 && $item['status'] == 0 && $item['refund_status'] == 0) {
  181. $item['_status'] = 1;
  182. } else if ($item['paid'] == 1 && $item['status'] == 0 && $item['refund_status'] == 0) {
  183. $item['_status'] = 2;
  184. } else if ($item['paid'] == 1 && $item['refund_status'] == 1) {
  185. $item['_status'] = 3;
  186. } else if ($item['paid'] == 1 && $item['status'] == 1 && $item['refund_status'] == 0) {
  187. $item['_status'] = 4;
  188. } else if ($item['paid'] == 1 && $item['status'] == 2 && $item['refund_status'] == 0) {
  189. $item['_status'] = 5;
  190. } else if ($item['paid'] == 1 && $item['status'] == 3 && $item['refund_status'] == 0) {
  191. $item['_status'] = 6;
  192. } else if ($item['paid'] == 1 && $item['refund_status'] == 2) {
  193. $item['_status'] = 7;
  194. }
  195. $item['spread_name'] = '';
  196. $item['spread_name_two'] = '';
  197. if ($item['type'] == 0) {
  198. if ($item['link_pay_uid']) {
  199. $spread_name = User::where('uid', $item['link_pay_uid'])->value('nickname');
  200. $item['spread_name'] = $spread_name ? $spread_name.'/'.$item['link_pay_uid'] : '无';
  201. $spread_uid_two = User::where('uid', $item['link_pay_uid'])->value('spread_uid');
  202. if ($spread_uid_two) {
  203. $spread_name_two = User::where('uid', $spread_uid_two)->value('nickname');
  204. $item['spread_name_two'] = $spread_name_two ? $spread_name_two.'/'.$spread_uid_two : '无';
  205. } else {
  206. $item['spread_name_two'] = '无';
  207. }
  208. } else if ($item['spread_uid']) {
  209. $spread_name = User::where('uid', $item['spread_uid'])->value('nickname');
  210. $item['spread_name'] = $spread_name ? $spread_name.'/'.$item['spread_uid'] : '无';
  211. $spread_uid_two = User::where('uid', $item['spread_uid'])->value('spread_uid');
  212. if ($spread_uid_two) {
  213. $spread_name_two = User::where('uid', $spread_uid_two)->value('nickname');
  214. $item['spread_name_two'] = $spread_name_two ? $spread_name_two.'/'.$spread_uid_two : '无';
  215. } else {
  216. $item['spread_name_two'] = '无';
  217. }
  218. } else {
  219. $item['spread_name'] = '无';
  220. $item['spread_name_two'] = '无';
  221. }
  222. }else{
  223. $item['spread_name'] = '不参与分销';
  224. $item['spread_name_two'] = '不参与分销';
  225. }
  226. }
  227. if (isset($where['excel']) && $where['excel'] == 1) {
  228. self::SaveExcel($data);
  229. }
  230. $count = self::getOrderWhere($where, self::alias('a')->join('user r', 'r.uid=a.uid', 'LEFT'), 'a.', 'r')->count();
  231. return compact('count', 'data');
  232. }
  233. /*
  234. * 保存并下载excel
  235. * $list array
  236. * return
  237. */
  238. public static function SaveExcel($list)
  239. {
  240. $export = [];
  241. foreach ($list as $index => $item) {
  242. $goodsName = '';
  243. if($item['type']==0){
  244. $special = self::getDb('special')->where('id', $item['cart_id'])->field('title,money')->find();
  245. if ($special){
  246. $goodsName = $special['title'] . '| ' . $special['money'];
  247. }else{
  248. $goodsName ='专题被删除';
  249. }
  250. $total='专题总数';
  251. $totalPrice ='专题总价';
  252. $information ='专题信息';
  253. }else if($item['type']==2){
  254. $_info = Db::name('store_order_cart_info')->where('oid', $item['id'])->column('cart_info');
  255. $goodsName = [];
  256. foreach ($_info as $k => $v) {
  257. $v = json_decode($v, true);
  258. $goodsName[] = implode(
  259. [$v['productInfo']['store_name'],
  260. isset($v['productInfo']['attrInfo']) ? '(' . $v['productInfo']['attrInfo']['suk'] . ')' : '',
  261. "[{$v['cart_num']} * {$v['truePrice']}]"
  262. ], ' ');
  263. }
  264. $item['cartInfo'] = $_info;
  265. $total='商品总数';
  266. $totalPrice ='商品总价';
  267. $information ='商品信息';
  268. }else if($item['type']==1){
  269. $_info=db('member_ship')->where('id', $item['member_id'])->find();
  270. if ($_info){
  271. $goodsName = $_info['title'] . '会员| ' . $_info['price'];
  272. }else{
  273. $goodsName ='会员信息被删除';
  274. }
  275. $total='会员总数';
  276. $totalPrice ='会员总价';
  277. $information ='会员信息';
  278. }
  279. if ($item['paid'] == 0 && $item['status'] == 0) {
  280. $item['status_name'] = '未支付';
  281. } else if ($item['paid'] == 1 && $item['status'] == 0 && $item['refund_status'] == 0 && $item['type'] != 2) {
  282. $item['status_name'] = '已支付';
  283. }else if ($item['paid'] == 1 && $item['status'] == 0 && $item['refund_status'] == 0 && $item['type'] == 2) {
  284. $item['status_name'] = '待发货';
  285. }else if ($item['paid'] == 1 && $item['status'] == 1 && $item['refund_status'] == 0 && $item['type'] == 2) {
  286. $item['status_name'] = '待收货';
  287. }else if ($item['paid'] == 1 && $item['status'] == 2 && $item['refund_status'] == 0 && $item['type'] == 2) {
  288. $item['status_name'] = '已完成';
  289. } else if ($item['paid'] == 1 && $item['refund_status'] == 1) {
  290. $item['status_name'] = '退款中';
  291. } else if ($item['paid'] == 1 && $item['refund_status'] == 2) {
  292. $item['status_name'] = '已退款';
  293. }
  294. $export[] = [
  295. $item['order_id'], $item['pay_type_name'],
  296. $item['total_num'], $item['total_price'], $item['total_postage'], $item['pay_price'], $item['refund_price'],
  297. $goodsName,
  298. $item['spread_name'],
  299. $item['spread_name_two'],
  300. [$item['paid'] == 1 ? '已支付' : '未支付', '支付时间: ' . ($item['pay_time'] > 0 ? date('Y/m/d H:i', $item['pay_time']) : '暂无')],
  301. $item['status_name'],
  302. $item['nickname'],
  303. $item['phone']
  304. ];
  305. }
  306. PHPExcelService::setExcelHeader(['订单号', '支付方式', $total, $totalPrice, '邮费', '支付金额', '退款金额', $information, '推广人', '推广人上级', '支付状态','订单状态', '微信昵称', '手机号'])
  307. ->setExcelTile('订单导出', '订单信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
  308. ->setExcelContent($export)
  309. ->ExcelSave();
  310. }
  311. public static function statusByWhere($status, $model = null, $alert = '',$type=0)
  312. {
  313. if ($model == null) $model = new self;
  314. switch ($type){
  315. case 0:
  316. $model=$model->where($alert . 'type', 0);
  317. break;
  318. case 1:
  319. $model=$model->where($alert . 'type', 1);
  320. break;
  321. case 2:
  322. $model=$model->where($alert . 'type', 2);
  323. break;
  324. }
  325. if ('' === $status)
  326. return $model;
  327. else if ($status == 0)//未支付
  328. return $model->where($alert . 'paid', 0)->where($alert . 'is_del', 0)->where($alert . 'status', 0)->where($alert . 'refund_status', 0);
  329. else if ($status == 1)//已支付 未发货
  330. return $model->where($alert . 'paid', 1)->where($alert . 'is_del', 0)->where($alert . 'status', 0)->where($alert . 'refund_status', 0);
  331. else if ($status == 2)//已支付 已发货
  332. return $model->where($alert . 'paid', 1)->where($alert . 'is_del', 0)->where($alert . 'status', 1)->where($alert . 'refund_status', 0);
  333. else if ($status == 3)//已支付 已完成
  334. return $model->where($alert . 'paid', 1)->where($alert . 'is_del', 0)->where($alert . 'status', 2)->where($alert . 'refund_status', 0);
  335. else if ($status == 5)//课程订单
  336. return $model->where($alert . 'combination_id', 0)->where($alert . 'is_del', 0)->where($alert . 'is_gift', 0);
  337. else if ($status == 6)// 拼团订单
  338. return $model->where($alert . 'combination_id','>', 0)->where($alert . 'is_del', 0)->where($alert . 'is_gift', 0);
  339. else if ($status == 7)// 礼物订单
  340. return $model->where($alert . 'combination_id', 0)->where($alert . 'is_del', 0)->where($alert . 'is_gift','>', 0);
  341. else if ($status == 8)//商品订单
  342. return $model->where($alert . 'combination_id', 0)->where($alert . 'is_del', 0)->where($alert . 'is_gift', 0);
  343. else if ($status == 9)//会员订单
  344. return $model->where($alert . 'combination_id', 0)->where($alert . 'is_del', 0)->where($alert . 'is_gift', 0);
  345. else if ($status == -1)//退款中
  346. return $model->where($alert . 'paid', 1)->where($alert . 'is_del', 0)->where($alert . 'refund_status', 1);
  347. else if ($status == -2)//已退款
  348. return $model->where($alert . 'paid', 1)->where($alert . 'is_del', 0)->where($alert . 'refund_status', 2);
  349. else
  350. return $model;
  351. }
  352. /**退金币
  353. * @param $data
  354. * @param $oid
  355. */
  356. public static function returnGoldCoin($oid)
  357. {
  358. $gold_name=SystemConfigService::get('gold_name');//虚拟币名称
  359. $order=self::where('id',$oid)->field('id,order_id,gain_gold_num,uid,type')->find();
  360. if($order['type']!=2) return true;
  361. if($order['gain_gold_num']>0){
  362. $uill=UserBill::where(['link_id'=>$order['id'],'pm'=>1,'category'=>'gold_num','type'=>'gain'])->find();
  363. if($uill){
  364. $userInfo = User::where('uid',$order['uid'])->find();
  365. if(bcsub($userInfo['gold_num'], $order['gain_gold_num'], 2)>0){
  366. $gold_num=bcsub($userInfo['gold_num'], $order['gain_gold_num'], 2);
  367. }else{
  368. $gold_num=0;
  369. }
  370. $res1=User::where('uid', $order['uid'])->update(['gold_num' =>$gold_num]);
  371. $res2=UserBill::expend($gold_name.'返还', $order['uid'], 'gold_num', 'return', $order['gain_gold_num'], $order['id'], $gold_num, '用户退款返还' . floatval($order['gain_gold_num']) . $gold_name);
  372. $res=$res1 && $res2;
  373. return $res;
  374. }else{
  375. return true;
  376. }
  377. }else{
  378. return true;
  379. }
  380. }
  381. /**退佣金 一级
  382. * @param $data
  383. * @param $oid
  384. */
  385. public static function returnCommissionOne($oid)
  386. {
  387. $order=self::where('id',$oid)->find();
  388. if($order['type']!=0) return true;
  389. $userInfo = User::where('uid',$order['uid'])->find();
  390. if (!$userInfo || !$userInfo['spread_uid']) return true;
  391. $storeBrokerageStatu = SystemConfigService::get('store_brokerage_statu') ?: 1;//获取后台分销类型
  392. if ($storeBrokerageStatu == 1) {
  393. if (!User::be(['uid' => $userInfo['spread_uid'], 'is_promoter' => 1])) return true;
  394. }
  395. $userInfoOne = User::where('uid',$userInfo['spread_uid'])->find();
  396. $uill=UserBill::where(['link_id'=>$order['id'],'pm'=>1,'uid'=>$userInfoOne['uid'],'category'=>'now_money','type'=>'brokerage'])->find();
  397. if($uill){
  398. if(bcsub($userInfoOne['brokerage_price'], $uill['number'], 2)>0){
  399. $brokerage_price=bcsub($userInfoOne['brokerage_price'], $uill['number'], 2);
  400. }else{
  401. $brokerage_price=0;
  402. }
  403. $res1=User::where('uid', $userInfoOne['uid'])->update(['brokerage_price' =>$brokerage_price]);
  404. $res2=UserBill::expend('佣金返还', $userInfoOne['uid'], 'now_money', 'brokerage_return', $uill['number'], $order['id'], $brokerage_price, '用户退款返还佣金' . floatval($uill['number']) .'元');
  405. $res=$res1 && $res2;
  406. if($res){
  407. return self::returnCommissionTwo($userInfoOne,$order);
  408. }
  409. }else{
  410. return true;
  411. }
  412. }
  413. /**退佣金 二级
  414. * @param $data
  415. * @param $oid
  416. */
  417. public static function returnCommissionTwo($userInfoOne,$order)
  418. {
  419. if (!$userInfoOne || !$userInfoOne['spread_uid']) return true;
  420. $storeBrokerageStatu = SystemConfigService::get('store_brokerage_statu') ?: 1;//获取后台分销类型
  421. if ($storeBrokerageStatu == 1) {
  422. if (!User::be(['uid' => $userInfoOne['spread_uid'], 'is_promoter' => 1])) return true;
  423. }
  424. $userInfoTwo = User::where('uid',$userInfoOne['spread_uid'])->find();
  425. $uill=UserBill::where(['link_id'=>$order['id'],'pm'=>1,'uid'=>$userInfoTwo['uid'],'category'=>'now_money','type'=>'brokerage'])->find();
  426. if($uill){
  427. if(bcsub($userInfoTwo['brokerage_price'], $uill['number'], 2)>0){
  428. $brokerage_price=bcsub($userInfoTwo['brokerage_price'], $uill['number'], 2);
  429. }else{
  430. $brokerage_price=0;
  431. }
  432. $res1=User::where('uid', $userInfoTwo['uid'])->update(['brokerage_price' =>$brokerage_price]);
  433. $res2=UserBill::expend('佣金返还', $userInfoTwo['uid'], 'now_money', 'brokerage_return', $uill['number'], $order['id'], $brokerage_price, '用户退款返还佣金' . floatval($uill['number']) .'元');
  434. $res=$res1 && $res2;
  435. return $res;
  436. }else{
  437. return true;
  438. }
  439. }
  440. public static function timeQuantumWhere($startTime = null, $endTime = null, $model = null)
  441. {
  442. if ($model === null) $model = new self;
  443. if ($startTime != null && $endTime != null)
  444. $model = $model->where('add_time', '>', strtotime($startTime))->where('add_time', '<', strtotime($endTime));
  445. return $model;
  446. }
  447. public static function changeOrderId($orderId)
  448. {
  449. $ymd = substr($orderId, 2, 8);
  450. $key = substr($orderId, 16);
  451. return 'wx' . $ymd . date('His') . $key;
  452. }
  453. /**
  454. * 线下付款
  455. * @param $id
  456. * @return $this
  457. */
  458. public static function updateOffline($id)
  459. {
  460. $orderId = self::where('id', $id)->value('order_id');
  461. $res = self::where('order_id', $orderId)->update(['paid' => 1, 'pay_time' => time()]);
  462. return $res;
  463. }
  464. /**
  465. * 退款发送模板消息
  466. * @param $oid
  467. * $oid 订单id key
  468. */
  469. public static function refundTemplate($data, $oid)
  470. {
  471. $order = self::where('id', $oid)->find();
  472. WechatTemplateService::sendTemplate(WechatUser::uidToOpenid($order['uid']), WechatTemplateService::ORDER_REFUND_STATUS, [
  473. 'first' => '亲,您购买的专题已退款,本次退款' . $data['refund_price'] . '金额',
  474. 'keyword1' => $order['order_id'],
  475. 'keyword2' => $order['pay_price'],
  476. 'keyword3' => date('Y-m-d H:i:s', $order['add_time']),
  477. 'remark' => '请查看账单'
  478. ], '');
  479. }
  480. /**
  481. * 处理where条件
  482. * @param $where
  483. * @param $model
  484. * @return mixed
  485. */
  486. public static function getOrderWhere($where, $model, $aler = '', $join = '')
  487. {
  488. if ($where['status'] != '') $model = self::statusByWhere($where['status'], $model, $aler,$where['types']);
  489. $model = $model->where($aler . 'is_del', $where['is_del']);
  490. if ($where['real_name'] != '') {
  491. $model = $model->where($aler . 'order_id|' . $aler . 'real_name|' . $aler . 'user_phone' . ($join ? '|' . $join . '.nickname|' . $join . '.uid|' . $join . '.phone' : ''), 'LIKE', "%$where[real_name]%");
  492. }
  493. $model = $model->where($aler . 'type', $where['types']);
  494. if($where['type'] != ''){
  495. switch ($where['type']){
  496. case 5:
  497. $model = $model->where($aler . 'combination_id', 0)->where($aler . 'is_gift', 0);
  498. break;
  499. case 6:
  500. $model = $model->where($aler . 'combination_id','>', 0)->where($aler . 'is_gift', 0);
  501. break;
  502. case 7:
  503. $model = $model->where($aler . 'combination_id', 0)->where($aler .'is_gift','>',0);
  504. break;
  505. case 8:
  506. $model = $model->where($aler . 'combination_id', 0)->where($aler .'is_gift',0);
  507. break;
  508. case 9:
  509. $model = $model->where($aler . 'combination_id', 0)->where($aler .'is_gift',0);
  510. break;
  511. }
  512. }
  513. if ($where['data'] !== '') {
  514. $model = self::getModelTime($where, $model, $aler . 'add_time');
  515. }
  516. return $model;
  517. }
  518. public static function getBadge($where)
  519. {
  520. $price = self::getOrderPrice($where);
  521. switch ($where['types']){
  522. case 0:
  523. $name='售出专题';
  524. break;
  525. case 1:
  526. $name='售出会员';
  527. break;
  528. case 2:
  529. $name='售出商品';
  530. break;
  531. }
  532. return [
  533. [
  534. 'name' => '订单数量',
  535. 'field' => '件',
  536. 'count' => $price['order_sum'],
  537. 'background_color' => 'layui-bg-blue',
  538. 'col' => 3
  539. ],
  540. [
  541. 'name' => $name,
  542. 'field' => '件',
  543. 'count' => $price['total_num'],
  544. 'background_color' => 'layui-bg-blue',
  545. 'col' => 3
  546. ],
  547. [
  548. 'name' => '订单金额',
  549. 'field' => '元',
  550. 'count' => $price['pay_price'],
  551. 'background_color' => 'layui-bg-blue',
  552. 'col' => 3
  553. ],
  554. [
  555. 'name' => '退款金额',
  556. 'field' => '元',
  557. 'count' => $price['refund_price'],
  558. 'background_color' => 'layui-bg-blue',
  559. 'col' => 3
  560. ],
  561. [
  562. 'name' => '微信支付金额',
  563. 'field' => '元',
  564. 'count' => $price['pay_price_wx'],
  565. 'background_color' => 'layui-bg-blue',
  566. 'col' => 3
  567. ],
  568. [
  569. 'name' => '余额支付金额',
  570. 'field' => '元',
  571. 'count' => $price['pay_price_yue'],
  572. 'background_color' => 'layui-bg-blue',
  573. 'col' => 3
  574. ],
  575. [
  576. 'name' => '支付宝支付金额',
  577. 'field' => '元',
  578. 'count' => $price['pay_price_zhifubao'],
  579. 'background_color' => 'layui-bg-blue',
  580. 'col' => 3
  581. ]
  582. ];
  583. }
  584. /**
  585. * 处理订单金额
  586. * @param $where
  587. * @return array
  588. */
  589. public static function getOrderPrice($where)
  590. {
  591. $model = new self;
  592. $price = array();
  593. $price['pay_price'] = 0;//支付金额
  594. $price['refund_price'] = 0;//退款金额
  595. $price['pay_price_wx'] = 0;//微信支付金额
  596. $price['pay_price_yue'] = 0;//余额支付金额
  597. $price['pay_price_offline'] = 0;//线下支付金额
  598. $price['pay_price_zhifubao'] = 0;//支付宝支付金额
  599. $price['pay_price_other'] = 0;//其他支付金额
  600. $list = self::getOrderWhere($where, $model)->field([
  601. 'sum(total_num) as total_num',
  602. 'sum(pay_price) as pay_price',
  603. 'sum(refund_price) as refund_price'])->find()->toArray();
  604. $price['total_num'] = $list['total_num'];//商品总数
  605. $price['pay_price'] = $list['pay_price'];//支付金额
  606. $price['refund_price'] = $list['refund_price'];//退款金额
  607. $list = self::getOrderWhere($where, $model)->field('sum(pay_price) as pay_price,pay_type')->group('pay_type')->select()->toArray();
  608. foreach ($list as $v) {
  609. if ($v['pay_type'] == 'weixin') {
  610. $price['pay_price_wx'] = $v['pay_price'];
  611. } elseif ($v['pay_type'] == 'yue') {
  612. $price['pay_price_yue'] = $v['pay_price'];
  613. } elseif ($v['pay_type'] == 'offline') {
  614. $price['pay_price_offline'] = $v['pay_price'];
  615. } elseif ($v['pay_type'] == 'zhifubao') {
  616. $price['pay_price_zhifubao'] = $v['pay_price'];
  617. } else {
  618. $price['pay_price_other'] = $v['pay_price'];
  619. }
  620. }
  621. $price['order_sum'] =self::getOrderWhere($where, $model)->count();
  622. return $price;
  623. }
  624. public static function systemPagePink($where)
  625. {
  626. $model = new self;
  627. $model = self::getOrderWherePink($where, $model);
  628. $model = $model->order('id desc');
  629. if ($where['export'] == 1) {
  630. $list = $model->select()->toArray();
  631. $export = [];
  632. foreach ($list as $index => $item) {
  633. if ($item['pay_type'] == 'weixin') {
  634. $payType = '微信支付';
  635. } elseif ($item['pay_type'] == 'yue') {
  636. $payType = '余额支付';
  637. } elseif ($item['pay_type'] == 'offline') {
  638. $payType = '线下支付';
  639. } else {
  640. $payType = '其他支付';
  641. }
  642. $_info = db('store_order_cart_info')->where('oid', $item['id'])->column('cart_info');
  643. $goodsName = [];
  644. foreach ($_info as $k => $v) {
  645. $v = json_decode($v, true);
  646. $goodsName[] = implode(
  647. [$v['productInfo']['store_name'],
  648. isset($v['productInfo']['attrInfo']) ? '(' . $v['productInfo']['attrInfo']['suk'] . ')' : '',
  649. "[{$v['cart_num']} * {$v['truePrice']}]"
  650. ], ' ');
  651. }
  652. $item['cartInfo'] = $_info;
  653. $export[] = [
  654. $item['order_id'], $payType,
  655. $item['total_num'], $item['total_price'], $item['total_postage'], $item['pay_price'], $item['refund_price'],
  656. $item['mark'], $item['remark'],
  657. [$item['real_name'], $item['user_phone'], $item['user_address']],
  658. $goodsName,
  659. [$item['paid'] == 1 ? '已支付' : '未支付', '支付时间: ' . ($item['pay_time'] > 0 ? date('Y/md H:i', $item['pay_time']) : '暂无')]
  660. ];
  661. $list[$index] = $item;
  662. }
  663. PHPExcelService::setExcelHeader(['订单号', '支付方式', '商品总数', '商品总价', '邮费', '支付金额', '退款金额', '用户备注', '管理员备注', '收货人信息', '商品信息', '支付状态'])
  664. ->setExcelTile('订单导出', '订单导出' . time())
  665. ->setExcelContent($export)
  666. ->ExcelSave();
  667. }
  668. return self::page($model, function ($item) {
  669. $item['nickname'] = WechatUser::where('uid', $item['uid'])->value('nickname');
  670. $_info = db('store_order_cart_info')->where('oid', $item['id'])->field('cart_info')->select();
  671. foreach ($_info as $k => $v) {
  672. $_info[$k]['cart_info'] = json_decode($v['cart_info'], true);
  673. }
  674. $item['_info'] = $_info;
  675. }, $where);
  676. }
  677. /**
  678. * 处理where条件
  679. * @param $where
  680. * @param $model
  681. * @return mixed
  682. */
  683. public static function getOrderWherePink($where, $model)
  684. {
  685. if ($where['status'] != '') $model = self::statusByWhere($where['status']);
  686. $model = $model->where('combination_id', 'GT', 0);
  687. if ($where['real_name'] != '') {
  688. $model = $model->where('order_id|real_name|user_phone', 'LIKE', "%$where[real_name]%");
  689. }
  690. if ($where['data'] !== '') {
  691. list($startTime, $endTime) = explode(' - ', $where['data']);
  692. $model = $model->where('add_time', '>', strtotime($startTime));
  693. $model = $model->where('add_time', '<', strtotime($endTime));
  694. }
  695. return $model;
  696. }
  697. /**
  698. * 处理订单金额
  699. * @param $where
  700. * @return array
  701. */
  702. public static function getOrderPricePink($where)
  703. {
  704. $model = new self;
  705. $price = array();
  706. $price['pay_price'] = 0;//支付金额
  707. $price['refund_price'] = 0;//退款金额
  708. $price['pay_price_wx'] = 0;//微信支付金额
  709. $price['pay_price_yue'] = 0;//余额支付金额
  710. $price['pay_price_offline'] = 0;//线下支付金额
  711. $price['pay_price_other'] = 0;//其他支付金额
  712. $price['use_integral'] = 0;//用户使用积分
  713. $price['back_integral'] = 0;//退积分总数
  714. $price['deduction_price'] = 0;//抵扣金额
  715. $price['total_num'] = 0; //商品总数
  716. $model = self::getOrderWherePink($where, $model);
  717. $list = $model->select()->toArray();
  718. foreach ($list as $v) {
  719. $price['total_num'] = bcadd($price['total_num'], $v['total_num'], 0);
  720. $price['pay_price'] = bcadd($price['pay_price'], $v['pay_price'], 2);
  721. $price['refund_price'] = bcadd($price['refund_price'], $v['refund_price'], 2);
  722. $price['use_integral'] = bcadd($price['use_integral'], $v['use_integral'], 2);
  723. $price['back_integral'] = bcadd($price['back_integral'], $v['back_integral'], 2);
  724. $price['deduction_price'] = bcadd($price['deduction_price'], $v['deduction_price'], 2);
  725. if ($v['pay_type'] == 'weixin') {
  726. $price['pay_price_wx'] = bcadd($price['pay_price_wx'], $v['pay_price'], 2);
  727. } elseif ($v['pay_type'] == 'yue') {
  728. $price['pay_price_yue'] = bcadd($price['pay_price_yue'], $v['pay_price'], 2);
  729. } elseif ($v['pay_type'] == 'offline') {
  730. $price['pay_price_offline'] = bcadd($price['pay_price_offline'], $v['pay_price'], 2);
  731. } else {
  732. $price['pay_price_other'] = bcadd($price['pay_price_other'], $v['pay_price'], 2);
  733. }
  734. }
  735. return $price;
  736. }
  737. /**
  738. * 获取昨天的订单 首页在使用
  739. * @param int $preDay
  740. * @param int $day
  741. * @return $this|StoreOrder
  742. */
  743. public static function isMainYesterdayCount($preDay = 0, $day = 0)
  744. {
  745. $model = new self();
  746. $model = $model->where('add_time', 'gt', $preDay);
  747. $model = $model->where('add_time', 'lt', $day);
  748. return $model;
  749. }
  750. /**
  751. * 获取用户购买次数
  752. * @param int $uid
  753. * @return int|string
  754. */
  755. public static function getUserCountPay($uid = 0)
  756. {
  757. if (!$uid) return 0;
  758. return self::where('uid', $uid)->where('paid', 1)->count();
  759. }
  760. /**
  761. * 获取单个用户购买列表
  762. * @param array $where
  763. * @return array
  764. */
  765. public static function getOneorderList($where)
  766. {
  767. return self::where(['uid' => $where['uid'], 'paid' => 1])
  768. ->order('add_time desc')
  769. ->page((int)$where['page'], (int)$where['limit'])
  770. ->field(['order_id', 'total_num', 'total_price', 'pay_price',
  771. 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time', 'paid', 'pay_type',
  772. 'pink_id'
  773. ])->select()
  774. ->toArray();
  775. }
  776. /*
  777. * 设置订单统计图搜索
  778. * $where array 条件
  779. * return object
  780. */
  781. public static function setEchatWhere($where, $status = null, $time = null)
  782. {
  783. $model = self::statusByWhere($where['status']);
  784. if ($status !== null) $where['type'] = $status;
  785. if ($time === true) $where['data'] = '';
  786. switch ($where['type']) {
  787. case 1:
  788. //普通商品
  789. $model = $model->where('combination_id', 0)->where('seckill_id', 0);
  790. break;
  791. case 2:
  792. //拼团商品
  793. $model = $model->where('combination_id', ">", 0)->where('pink_id', ">", 0);
  794. break;
  795. case 3:
  796. //秒杀商品
  797. $model = $model->where('seckill_id', ">", 0);
  798. break;
  799. case 4:
  800. //砍价商品
  801. $model = $model->where('bargain_id', '>', 0);
  802. break;
  803. }
  804. return self::getModelTime($where, $model);
  805. }
  806. /*
  807. * 获取订单数据统计图
  808. * $where array
  809. * $limit int
  810. * return array
  811. */
  812. public static function getEchartsOrder($where, $limit = 20)
  813. {
  814. $orderlist = self::setEchatWhere($where)->field([
  815. 'FROM_UNIXTIME(add_time,"%Y-%m-%d") as _add_time',
  816. 'sum(total_num) total_num',
  817. 'count(*) count',
  818. 'sum(total_price) total_price',
  819. 'sum(refund_price) refund_price',
  820. 'group_concat(cart_id SEPARATOR "|") cart_ids'
  821. ])->group('_add_time')->order('_add_time asc')->select();
  822. count($orderlist) && $orderlist = $orderlist->toArray();
  823. $legend = ['商品数量', '订单数量', '订单金额', '退款金额'];
  824. $seriesdata = [
  825. [
  826. 'name' => $legend[0],
  827. 'type' => 'line',
  828. 'data' => [],
  829. ],
  830. [
  831. 'name' => $legend[1],
  832. 'type' => 'line',
  833. 'data' => []
  834. ],
  835. [
  836. 'name' => $legend[2],
  837. 'type' => 'line',
  838. 'data' => []
  839. ],
  840. [
  841. 'name' => $legend[3],
  842. 'type' => 'line',
  843. 'data' => []
  844. ]
  845. ];
  846. $xdata = [];
  847. $zoom = '';
  848. foreach ($orderlist as $item) {
  849. $xdata[] = $item['_add_time'];
  850. $seriesdata[0]['data'][] = $item['total_num'];
  851. $seriesdata[1]['data'][] = $item['count'];
  852. $seriesdata[2]['data'][] = $item['total_price'];
  853. $seriesdata[3]['data'][] = $item['refund_price'];
  854. }
  855. count($xdata) > $limit && $zoom = $xdata[$limit - 5];
  856. $badge = self::getOrderBadge($where);
  857. $bingpaytype = self::setEchatWhere($where)->group('pay_type')->field(['count(*) as count', 'pay_type'])->select();
  858. count($bingpaytype) && $bingpaytype = $bingpaytype->toArray();
  859. $bing_xdata = ['微信支付', '余额支付', '其他支付'];
  860. $color = ['#ffcccc', '#99cc00', '#fd99cc', '#669966'];
  861. $bing_data = [];
  862. foreach ($bingpaytype as $key => $item) {
  863. if ($item['pay_type'] == 'weixin') {
  864. $value['name'] = $bing_xdata[0];
  865. } else if ($item['pay_type'] == 'yue') {
  866. $value['name'] = $bing_xdata[1];
  867. } else {
  868. $value['name'] = $bing_xdata[2];
  869. }
  870. $value['value'] = $item['count'];
  871. $value['itemStyle']['color'] = isset($color[$key]) ? $color[$key] : $color[0];
  872. $bing_data[] = $value;
  873. }
  874. return compact('zoom', 'xdata', 'seriesdata', 'badge', 'legend', 'bing_data', 'bing_xdata');
  875. }
  876. public static function getOrderBadge($where)
  877. {
  878. return [
  879. [
  880. 'name' => '拼团订单数量',
  881. 'field' => '个',
  882. 'count' => self::setEchatWhere($where, 2)->count(),
  883. 'content' => '拼团总订单数量',
  884. 'background_color' => 'layui-bg-cyan',
  885. 'sum' => self::setEchatWhere($where, 2, true)->count(),
  886. 'class' => 'fa fa-line-chart',
  887. 'col' => 2
  888. ],
  889. [
  890. 'name' => '砍价订单数量',
  891. 'field' => '个',
  892. 'count' => self::setEchatWhere($where, 4)->count(),
  893. 'content' => '砍价总订单数量',
  894. 'background_color' => 'layui-bg-cyan',
  895. 'sum' => self::setEchatWhere($where, 4, true)->count(),
  896. 'class' => 'fa fa-line-chart',
  897. 'col' => 2
  898. ],
  899. [
  900. 'name' => '秒杀订单数量',
  901. 'field' => '个',
  902. 'count' => self::setEchatWhere($where, 3)->count(),
  903. 'content' => '秒杀总订单数量',
  904. 'background_color' => 'layui-bg-cyan',
  905. 'sum' => self::setEchatWhere($where, 3, true)->count(),
  906. 'class' => 'fa fa-line-chart',
  907. 'col' => 2
  908. ],
  909. [
  910. 'name' => '普通订单数量',
  911. 'field' => '个',
  912. 'count' => self::setEchatWhere($where, 1)->count(),
  913. 'content' => '普通总订单数量',
  914. 'background_color' => 'layui-bg-cyan',
  915. 'sum' => self::setEchatWhere($where, 1, true)->count(),
  916. 'class' => 'fa fa-line-chart',
  917. 'col' => 2,
  918. ],
  919. [
  920. 'name' => '使用优惠卷金额',
  921. 'field' => '元',
  922. 'count' => self::setEchatWhere($where)->sum('coupon_price'),
  923. 'content' => '普通总订单数量',
  924. 'background_color' => 'layui-bg-cyan',
  925. 'sum' => self::setEchatWhere($where, null, true)->sum('coupon_price'),
  926. 'class' => 'fa fa-line-chart',
  927. 'col' => 2
  928. ],
  929. [
  930. 'name' => '积分消耗数',
  931. 'field' => '个',
  932. 'count' => self::setEchatWhere($where)->sum('use_integral'),
  933. 'content' => '积分消耗总数',
  934. 'background_color' => 'layui-bg-cyan',
  935. 'sum' => self::setEchatWhere($where, null, true)->sum('use_integral'),
  936. 'class' => 'fa fa-line-chart',
  937. 'col' => 2
  938. ],
  939. [
  940. 'name' => '积分抵扣金额',
  941. 'field' => '个',
  942. 'count' => self::setEchatWhere($where)->sum('deduction_price'),
  943. 'content' => '积分抵扣总金额',
  944. 'background_color' => 'layui-bg-cyan',
  945. 'sum' => self::setEchatWhere($where, null, true)->sum('deduction_price'),
  946. 'class' => 'fa fa-money',
  947. 'col' => 2
  948. ],
  949. [
  950. 'name' => '在线支付金额',
  951. 'field' => '元',
  952. 'count' => self::setEchatWhere($where)->where('pay_type', 'weixin')->sum('pay_price'),
  953. 'content' => '在线支付总金额',
  954. 'background_color' => 'layui-bg-cyan',
  955. 'sum' => self::setEchatWhere($where, null, true)->where('pay_type', 'weixin')->sum('pay_price'),
  956. 'class' => 'fa fa-weixin',
  957. 'col' => 2
  958. ],
  959. [
  960. 'name' => '余额支付金额',
  961. 'field' => '元',
  962. 'count' => self::setEchatWhere($where)->where('pay_type', 'yue')->sum('pay_price'),
  963. 'content' => '余额支付总金额',
  964. 'background_color' => 'layui-bg-cyan',
  965. 'sum' => self::setEchatWhere($where, null, true)->where('pay_type', 'yue')->sum('pay_price'),
  966. 'class' => 'fa fa-balance-scale',
  967. 'col' => 2
  968. ],
  969. [
  970. 'name' => '赚取积分',
  971. 'field' => '分',
  972. 'count' => self::setEchatWhere($where)->sum('gain_integral'),
  973. 'content' => '赚取总积分',
  974. 'background_color' => 'layui-bg-cyan',
  975. 'sum' => self::setEchatWhere($where, null, true)->sum('gain_integral'),
  976. 'class' => 'fa fa-gg-circle',
  977. 'col' => 2
  978. ],
  979. [
  980. 'name' => '交易额',
  981. 'field' => '元',
  982. 'count' => self::setEchatWhere($where)->sum('pay_price'),
  983. 'content' => '总交易额',
  984. 'background_color' => 'layui-bg-cyan',
  985. 'sum' => self::setEchatWhere($where, null, true)->sum('pay_price'),
  986. 'class' => 'fa fa-jpy',
  987. 'col' => 2
  988. ],
  989. [
  990. 'name' => '订单商品数量',
  991. 'field' => '元',
  992. 'count' => self::setEchatWhere($where)->sum('total_num'),
  993. 'content' => '订单商品总数量',
  994. 'background_color' => 'layui-bg-cyan',
  995. 'sum' => self::setEchatWhere($where, null, true)->sum('total_num'),
  996. 'class' => 'fa fa-cube',
  997. 'col' => 2
  998. ]
  999. ];
  1000. }
  1001. /**
  1002. * 获取订单总数
  1003. * @param int $uid
  1004. * @return int|string
  1005. */
  1006. public static function getOrderCount($uid = 0)
  1007. {
  1008. if (!$uid) return 0;
  1009. return self::where('uid', $uid)->where('paid', 1)->where('refund_status', 0)->where('status', 2)->count();
  1010. }
  1011. }