OtherOrderServices.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  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\OtherOrderDao;
  13. use app\services\BaseServices;
  14. use app\services\pay\PayServices;
  15. use app\services\statistic\CapitalFlowServices;
  16. use app\services\user\member\MemberShipServices;
  17. use app\services\user\UserBillServices;
  18. use app\services\user\UserBrokerageServices;
  19. use app\services\user\UserServices;
  20. use app\services\user\member\MemberCardServices;
  21. use crmeb\exceptions\ApiException;
  22. use think\App;
  23. use app\jobs\OtherOrderJob;
  24. /**
  25. * Class OtherOrderServices
  26. * @package app\services\order
  27. * @method getDistinctCount(array $where, $field, ?bool $search = true)
  28. * @method getPayUserCount(int $time, string $channel_type)
  29. * @method getTrendData($time, $type, $timeType)
  30. */
  31. class OtherOrderServices extends BaseServices
  32. {
  33. /**
  34. * 初始化,获得dao层句柄
  35. * OtherOrderServices constructor.
  36. * @param OtherOrderDao $dao
  37. */
  38. public function __construct(OtherOrderDao $dao)
  39. {
  40. $this->dao = $dao;
  41. }
  42. /**
  43. * 生成会员购买订单数据
  44. * @param array $data
  45. * @return mixed
  46. */
  47. public function addOtherOrderData(array $data)
  48. {
  49. if (!$data) throw new ApiException(100026);
  50. $add = [
  51. 'uid' => $data['uid'],
  52. 'type' => $data['type'] ?? 1,
  53. 'order_id' => $data['order_id'],
  54. 'channel_type' => $data['channel_type'],
  55. 'pay_type' => $data['pay_type'] ?? 0,
  56. 'member_type' => $data['member_type'] ?? 0,
  57. 'member_price' => $data['member_price'] ?? 0.00,
  58. 'pay_price' => $data['pay_price'] ?? 0.00,
  59. 'code' => $data['member_code'] ?? "",
  60. 'vip_day' => $data['vip_day'] ?? 0,
  61. 'is_permanent' => $data['is_permanent'] ?? 0,
  62. 'is_free' => $data['is_free'] ?? 0,
  63. 'overdue_time' => $data['overdue_time'] ?? 0,
  64. 'status' => 0,
  65. 'paid' => $data['paid'] ?? 0,
  66. 'pay_time' => $data['pay_time'] ?? 0,
  67. 'money' => $data['money'] ?? 0,
  68. 'add_time' => time(),
  69. ];
  70. return $this->dao->save($add);
  71. }
  72. /**
  73. * 能否领取免费
  74. * @param int $uid
  75. * @return array
  76. * @throws \think\db\exception\DataNotFoundException
  77. * @throws \think\db\exception\DbException
  78. * @throws \think\db\exception\ModelNotFoundException
  79. */
  80. public function isCanGetFree(int $uid)
  81. {
  82. /** @var UserServices $userService */
  83. $userService = app()->make(UserServices::class);
  84. /** @var MemberShipServices $memberShipService */
  85. $memberShipService = app()->make(MemberShipServices::class);
  86. /** @var StoreOrderEconomizeServices $economizeService */
  87. $economizeService = app()->make(StoreOrderEconomizeServices::class);
  88. $freeDay = $memberShipService->getVipDay(['type' => "free"]);
  89. $freeConfig = array();
  90. $freeConfig['price'] = 0;
  91. $freeConfig['pre_price'] = 0;
  92. $freeConfig['title'] = "免费会员";
  93. $freeConfig['type'] = "free";
  94. $freeConfig['vip_day'] = $freeDay ?: 0;
  95. $userInfo = $userService->get($uid);
  96. if ($freeConfig) {
  97. $freeConfig['is_record'] = 0;
  98. $record = $this->dao->getOneByWhere(['uid' => $uid, 'is_free' => 1]);
  99. if ($record) {
  100. $freeConfig['is_record'] = 1;
  101. }
  102. }
  103. $registerTime = $this->TimeConvert(['start_time' => date('Y-m-d H:i:s', $userInfo['add_time']), 'end_time' => date('Y-m-d H:i:s', time())]);
  104. $userInfo['register_days'] = $registerTime['days'];
  105. $userInfo['economize_money'] = $economizeService->sumEconomizeMoney($uid);
  106. $userInfo['shop_name'] = sys_config('site_name');
  107. $freeConfig['user_info'] = $userInfo;
  108. return $freeConfig;
  109. }
  110. /**搜索时间转换
  111. * @param $timeKey
  112. * @param bool $isNum
  113. * @throws \Exception
  114. */
  115. public function TimeConvert($timeKey, $isNum = false)
  116. {
  117. switch ($timeKey) {
  118. case "today" :
  119. $data['start_time'] = date('Y-m-d 00:00:00', time());
  120. $data['end_time'] = date('Y-m-d 23:59:59', time());
  121. $data['days'] = 1;
  122. break;
  123. case "yestoday" :
  124. $data['start_time'] = date('Y-m-d 00:00:00', strtotime('-1 day'));
  125. $data['end_time'] = date('Y-m-d 23:59:59', strtotime('-1 day'));
  126. $data['days'] = 1;
  127. break;
  128. case "last_month" :
  129. $data['start_time'] = date('Y-m-01 00:00:00', strtotime('-1 month'));
  130. $data['end_time'] = date('Y-m-t 23:59:59', strtotime('-1 month'));
  131. $data['days'] = 30;
  132. break;
  133. case "month" :
  134. $data['start_time'] = $month_start_time = date('Y-m-01 00:00:00', strtotime(date("Y-m-d")));
  135. $data['end_time'] = date('Y-m-d 23:59:59', strtotime("$month_start_time +1 month -1 day"));
  136. $data['days'] = 30;
  137. break;
  138. case "year" :
  139. $data['start_time'] = date('Y-01-01 00:00:00', time());
  140. $data['end_time'] = date('Y-12-t 23:59:59', time());
  141. $data['days'] = 365;
  142. break;
  143. case "last_year" :
  144. $data['start_time'] = date('Y-01-01 00:00:00', strtotime('-1 year'));
  145. $data['end_time'] = date('Y-12-t 23:59:59', strtotime('-1 year'));
  146. $data['days'] = 365;
  147. break;
  148. case 30 :
  149. case 15 :
  150. case 7 :
  151. if (!$isNum) {
  152. $data['start_time'] = date("Y-m-d 00:00:00", strtotime("-$timeKey day"));
  153. $data['end_time'] = date('Y-m-d 23:59:59', time());
  154. $data['days'] = $timeKey;
  155. } else {
  156. $day = $timeKey * 2;
  157. $data['start_time'] = date("Y-m-d 00:00:00", strtotime("-$day day"));
  158. $data['end_time'] = date("Y-m-d 23:59:59", strtotime("-$timeKey day"));
  159. $data['days'] = $timeKey;
  160. }
  161. break;
  162. default:
  163. $datetime_start = new \DateTime($timeKey['start_time']);
  164. $datetime_end = new \DateTime($timeKey['end_time']);
  165. $days = $datetime_start->diff($datetime_end)->days;
  166. $days = $days > 0 ? $days : 1;
  167. if (!$isNum) {
  168. $data['start_time'] = $timeKey['start_time'];
  169. $data['end_time'] = $timeKey['end_time'];
  170. $data['days'] = $days;
  171. } else {
  172. $data['start_time'] = date("Y-m-d 00:00:00", strtotime("-$days day"));
  173. $data['end_time'] = $timeKey['start_time'];
  174. $data['days'] = $days;
  175. }
  176. }
  177. return $data;
  178. }
  179. /**
  180. * 查询会员卡订单数据
  181. * @param array $where
  182. * @param string $field
  183. * @return array|\think\Model|null
  184. * @throws \think\db\exception\DataNotFoundException
  185. * @throws \think\db\exception\DbException
  186. * @throws \think\db\exception\ModelNotFoundException
  187. */
  188. public function getOne(array $where, string $field = '*')
  189. {
  190. return $this->dao->getOne($where, $field);
  191. }
  192. /**
  193. * @param int $uid
  194. * @param string $channelType 支付渠道
  195. * @param bool $memberType 会员卡类型
  196. * @param string $payPrice 支付金额
  197. * @param string $payType 支付方式
  198. * @param $type 订单类型
  199. * @return mixed
  200. * @throws \Exception
  201. */
  202. public function createOrder(int $uid, string $channelType, $memberType = false, string $payPrice, string $payType, $type, $money, $mcId)
  203. {
  204. /** @var StoreOrderCreateServices $storeOrderCreateService */
  205. $storeOrderCreateService = app()->make(StoreOrderCreateServices::class);
  206. $orderInfo = [
  207. 'uid' => $uid,
  208. 'order_id' => $storeOrderCreateService->getNewOrderId('hy'),
  209. 'pay_price' => $payPrice,
  210. 'pay_type' => $payType,
  211. 'channel_type' => $channelType,
  212. 'member_code' => "",
  213. ];
  214. if ($type != 3) { //区别 0:免费领取会员 1:购买会员 2:卡密领取会员 3:线下付款
  215. if (!$memberType) throw new ApiException(410228);
  216. list($memberPrice, $isFree, $isPermanent, $overdueTime, $type, $newMemberRight) = $this->checkPayMemberType($memberType, $payPrice, $type, $uid, $mcId);
  217. $orderInfo['member_price'] = $memberPrice;
  218. $orderInfo['money'] = $memberPrice;
  219. $orderInfo['vip_day'] = $newMemberRight[$mcId]['vip_day'];
  220. $orderInfo['member_type'] = $memberType;
  221. $orderInfo['overdue_time'] = $overdueTime;
  222. $orderInfo['is_permanent'] = $isPermanent;
  223. $orderInfo['is_free'] = $isFree;
  224. $orderInfo['type'] = $type;
  225. $changeType = "create_member_order";
  226. } else {
  227. $orderInfo['type'] = $type;
  228. $orderInfo['member_code'] = "";
  229. $changeType = "create_offline_scan_order";
  230. $orderInfo['money'] = $money ?: $payPrice;
  231. }
  232. $memberOrder = $this->addOtherOrderData($orderInfo);
  233. if (!$memberOrder) {
  234. throw new ApiException(410200);
  235. }
  236. /** @var OtherOrderStatusServices $statusService */
  237. $statusService = app()->make(OtherOrderStatusServices::class);
  238. $statusService->save([
  239. 'oid' => $memberOrder['id'],
  240. 'change_type' => $changeType,
  241. 'change_message' => '订单生成',
  242. 'change_time' => time(),
  243. 'shop_type' => $type,
  244. ]);
  245. return $memberOrder;
  246. }
  247. /**
  248. * 免费卡领取支付
  249. * @param $orderInfo
  250. * @return bool
  251. */
  252. public function zeroYuanPayment($orderInfo)
  253. {
  254. if ($orderInfo['paid']) {
  255. throw new ApiException(410174);
  256. }
  257. if ($orderInfo['member_type'] != 'free') {
  258. throw new ApiException(410216);
  259. }
  260. $res = $this->paySuccess($orderInfo, 'yue');//余额支付成功
  261. return $res;
  262. }
  263. /**
  264. * 会员卡支付成功
  265. * @param array $orderInfo
  266. * @param string $paytype
  267. * @return bool
  268. */
  269. public function paySuccess(array $orderInfo, string $paytype = PayServices::WEIXIN_PAY, array $other = [])
  270. {
  271. /** @var OtherOrderStatusServices $statusService */
  272. $statusService = app()->make(OtherOrderStatusServices::class);
  273. /** @var UserServices $userServices */
  274. $userServices = app()->make(UserServices::class);
  275. /** @var UserBillServices $userBillServices */
  276. $userBillServices = app()->make(UserBillServices::class);
  277. $type = 'pay_member';
  278. $res1 = true;
  279. switch ($orderInfo['type']) {
  280. case 0 :
  281. case 1 :
  282. case 2 :
  283. $type = "pay_member";
  284. $res1 = $userServices->setMemberOverdueTime($orderInfo['vip_day'], $orderInfo['uid'], 1, $orderInfo['member_type']);
  285. break;
  286. case 3:
  287. $type = "offline_scan";
  288. $res1 = true;
  289. break;
  290. }
  291. if ($paytype == PayServices::ALIAPY_PAY && isset($other['trade_no'])) {
  292. $updata['trade_no'] = $other['trade_no'];
  293. }
  294. $updata['paid'] = 1;
  295. $updata['pay_type'] = $paytype;
  296. $updata['pay_time'] = time();
  297. $orderInfo['pay_time'] = $updata['pay_time'];
  298. $res2 = $this->dao->update($orderInfo['id'], $updata);
  299. $res3 = $statusService->save([
  300. 'oid' => $orderInfo['id'],
  301. 'change_type' => 'pay_success',
  302. 'change_message' => '用户付款成功',
  303. 'shop_type' => $orderInfo['type'],
  304. 'change_time' => time()
  305. ]);
  306. $now_money = $userServices->value(['uid' => $orderInfo['uid']], 'now_money');
  307. $res4 = $userBillServices->income($type, $orderInfo['uid'], $orderInfo['pay_price'], $now_money, $orderInfo['id']);
  308. //支付成功后发送消息
  309. OtherOrderJob::dispatch([$orderInfo]);
  310. $orderInfo['is_channel'] = 2;
  311. $orderInfo['total_num'] = 1;
  312. if ($orderInfo['pay_type'] != 'yue') {
  313. /** @var CapitalFlowServices $capitalFlowServices */
  314. $capitalFlowServices = app()->make(CapitalFlowServices::class);
  315. $userInfo = $userServices->get($orderInfo['uid']);
  316. $orderInfo['nickname'] = $userInfo['nickname'];
  317. $orderInfo['phone'] = $userInfo['phone'];
  318. $capitalFlowServices->setFlow($orderInfo, $type);
  319. }
  320. $res = $res1 && $res2 && $res3 && $res4;
  321. //购买付费会员返佣设置
  322. if (sys_config('member_brokerage', 0) == 1 && sys_config('brokerage_func_status', 0) == 1) {
  323. $spread_one = sys_config('is_self_brokerage') ? $orderInfo['uid'] : $userServices->getSpreadUid($orderInfo['uid']);
  324. $spread_two = sys_config('brokerage_level', 2) == 2 ? $userServices->getSpreadUid($spread_one) : 0;
  325. $spread_one_price = bcmul((string)$orderInfo['pay_price'], (string)bcdiv((string)sys_config('store_brokerage_ratio', 0), '100', 4), 2);
  326. $spread_two_price = bcmul((string)$orderInfo['pay_price'], (string)bcdiv((string)sys_config('store_brokerage_two', 0), '100', 4), 2);
  327. if ($spread_one && $spread_one_price > 0) $this->memberBrokerage($spread_one, $spread_one_price, sys_config('is_self_brokerage') ? 'get_self_member_brokerage' : 'get_member_brokerage', $orderInfo);
  328. if ($spread_two && $spread_two_price > 0) $this->memberBrokerage($spread_two, $spread_two_price, 'get_two_member_brokerage', $orderInfo);
  329. }
  330. $orderInfo['pay_type'] = $paytype;
  331. // 小程序订单服务
  332. event('OrderShipping', ['member', $orderInfo, 3, '', '']);
  333. return false !== $res;
  334. }
  335. /**
  336. * 购买付费会员返佣
  337. * @param $uid
  338. * @param $price
  339. * @param $type
  340. * @param $orderInfo
  341. */
  342. public function memberBrokerage($uid, $price, $type, $orderInfo)
  343. {
  344. /** @var UserServices $userServices */
  345. $userServices = app()->make(UserServices::class);
  346. $userInfo = $userServices->get($uid);
  347. // 上级推广员返佣之后的金额
  348. $balance = bcadd($userInfo['brokerage_price'], $price, 2);
  349. // 添加用户佣金
  350. $res1 = $userServices->bcInc($uid, 'brokerage_price', $price, 'uid');
  351. if ($res1) {
  352. //冻结时间
  353. $broken_time = intval(sys_config('extract_time'));
  354. $frozen_time = time() + $broken_time * 86400;
  355. // 添加佣金记录
  356. /** @var UserBrokerageServices $userBrokerageServices */
  357. $userBrokerageServices = app()->make(UserBrokerageServices::class);
  358. $userBrokerageServices->income($type, $uid, [
  359. 'nickname' => $userInfo['nickname'],
  360. 'pay_price' => floatval($orderInfo['pay_price']),
  361. 'number' => floatval($price),
  362. 'frozen_time' => $frozen_time
  363. ], $balance, $orderInfo['id']);
  364. }
  365. }
  366. /**
  367. * 修改
  368. * @param $where
  369. * @param array $data
  370. * @return \crmeb\basic\BaseModel
  371. */
  372. public function update($where, array $data)
  373. {
  374. return $this->dao->update($where, $data);
  375. }
  376. /**
  377. * 购买会员卡数据校验
  378. * @param string $memberType
  379. * @param string $payPrice
  380. * @param string $type
  381. * @param $uid
  382. * @param $mcId
  383. * @return array
  384. * @throws \think\db\exception\DataNotFoundException
  385. * @throws \think\db\exception\DbException
  386. * @throws \think\db\exception\ModelNotFoundException
  387. */
  388. public function checkPayMemberType(string $memberType, string $payPrice, string $type, $uid, $mcId)
  389. {
  390. /** @var MemberCardServices $memberCardService */
  391. $memberCardService = app()->make(MemberCardServices::class);
  392. /** @var UserServices $userService */
  393. $userService = app()->make(UserServices::class);
  394. $userInfo = $userService->get($uid);
  395. if ($userInfo['is_money_level'] > 0 && $userInfo['is_ever_level'] > 0) throw new ApiException(410229);
  396. $newMemberRight = $memberCardService->getMemberTypeValue();
  397. if (!array_key_exists($mcId, $newMemberRight)) throw new ApiException(410230);
  398. $price = $newMemberRight[$mcId]['pre_price'];
  399. if ($payPrice != $price || ($memberType != 'free' && $payPrice <= 0)) throw new ApiException(100100);
  400. if ($memberType == 'free' && $newMemberRight[$mcId]['vip_day'] <= 0) throw new ApiException(100100);
  401. switch ($memberType) {
  402. case "free"://免费会员
  403. $isCanGetFree = $this->isCanGetFree($uid);
  404. if ($isCanGetFree['is_record'] == 1) throw new ApiException(410231);
  405. $memberPrice = 0.00; //会员卡价格
  406. $isFree = 1;//代表免费
  407. $isPermanent = 0;//代表非永久
  408. $overdueTime = bcadd(bcmul(abs($newMemberRight[$mcId]['vip_day']), "86400", 0), time(), 0);
  409. break;
  410. case "month":
  411. case "year":
  412. case "quarter":
  413. case "owner":
  414. $memberPrice = $price;
  415. $isFree = 0;
  416. $isPermanent = 0;
  417. $overdueTime = bcadd(bcmul(abs($newMemberRight[$mcId]['vip_day']), '86400', 0), time(), 0);
  418. break;
  419. case "ever":
  420. $memberPrice = $price;
  421. $isFree = 0;
  422. $isPermanent = 1;
  423. $overdueTime = -1;
  424. break;
  425. default:
  426. throw new ApiException(410232);
  427. }
  428. //return compact('member_price', 'is_free', 'is_permanent', 'overdue_time', 'type');
  429. return [$memberPrice, $isFree, $isPermanent, $overdueTime, $type, $newMemberRight];
  430. }
  431. /**
  432. * 根据查询用户购买会员金额
  433. * @param array $where
  434. * @return mixed
  435. */
  436. public function getMemberMoneyByWhere(array $where, string $sumField, string $selectType, string $group = "")
  437. {
  438. switch ($selectType) {
  439. case "sum" :
  440. return $this->dao->getWhereSumField($where, $sumField);
  441. case "group" :
  442. return $this->dao->getGroupField($where, $sumField, $group);
  443. }
  444. }
  445. /**
  446. * 线下收银列表
  447. * @param array $where
  448. * @return array
  449. * @throws \think\db\exception\DataNotFoundException
  450. * @throws \think\db\exception\DbException
  451. * @throws \think\db\exception\ModelNotFoundException
  452. */
  453. public function getScanOrderList(array $where)
  454. {
  455. $where['type'] = 3;
  456. $where['paid'] = 1;
  457. [$page, $limit] = $this->getPageValue();
  458. if ($where['add_time']) {
  459. [$startTime, $endTime] = explode('-', $where['add_time']);
  460. if ($startTime || $endTime) {
  461. $startTime = strtotime($startTime);
  462. $endTime = strtotime($endTime . ' 23:59:59');
  463. $where['add_time'] = [$startTime, $endTime];
  464. }
  465. }
  466. if ($where['name']) {
  467. /** @var UserServices $userService */
  468. $userService = app()->make(UserServices::class);
  469. $userInfo = $userService->getUserInfoList(['nickname' => $where['name']], "uid");
  470. if ($userInfo) $where['uid'] = array_column($userInfo, 'uid');
  471. }
  472. $list = $this->dao->getScanOrderList($where, $page, $limit);
  473. if ($list) {
  474. /** @var UserServices $userService */
  475. $userService = app()->make(UserServices::class);
  476. $userInfo = $userService->getColumn([['uid', 'in', array_unique(array_column($list, 'uid'))]], 'uid,phone,nickname', 'uid');
  477. foreach ($list as &$v) {
  478. $v['add_time'] = date('Y-m-d H:i:s', $v['add_time']);
  479. $v['pay_time'] = date('Y-m-d H:i:s', $v['pay_time']);
  480. $v['phone'] = $userInfo[$v['uid']]['phone'] ?? '';
  481. $v['nickname'] = $userInfo[$v['uid']]['nickname'] ?? '';
  482. switch ($v['pay_type']) {
  483. case "yue" :
  484. $v['pay_type'] = "余额";
  485. break;
  486. case "weixin" :
  487. $v['pay_type'] = "微信";
  488. break;
  489. case "alipay" :
  490. $v['pay_type'] = "支付宝";
  491. break;
  492. }
  493. $v['true_price'] = bcsub($v['money'], $v['pay_price'], 2);
  494. }
  495. }
  496. $count = $this->dao->count($where);
  497. return compact('list', 'count');
  498. }
  499. /**
  500. * 获取会员记录
  501. * @param array $where
  502. * @return array
  503. * @throws \think\db\exception\DataNotFoundException
  504. * @throws \think\db\exception\DbException
  505. * @throws \think\db\exception\ModelNotFoundException
  506. */
  507. public function getMemberRecord(array $where)
  508. {
  509. $where['type'] = [0, 1, 2];
  510. $where['paid'] = 1;
  511. if ($where['add_time']) {
  512. $searchTime = explode('-', $where['add_time']);
  513. $startTime = strtotime($searchTime[0]);
  514. $endTime = strtotime($searchTime[1]);
  515. if ($startTime == $endTime) {
  516. $endTime += 86400;
  517. }
  518. $where['add_time'] = [$startTime, $endTime];
  519. }
  520. [$page, $limit] = $this->getPageValue();
  521. $list = $this->dao->getMemberRecord($where, $page, $limit);
  522. if ($list) {
  523. /** @var MemberShipServices $memberShipService */
  524. $memberShipService = app()->make(MemberShipServices::class);
  525. $shipInfo = $memberShipService->getApiList([]);
  526. $shipInfo = array_column($shipInfo, 'title', 'type');
  527. $shipInfo['owner'] = '自定义';
  528. foreach ($list as &$v) {
  529. $v['member_type'] = $v['member_type'] ? $shipInfo[$v['member_type']] : '其他';
  530. $v['pay_time'] = date('Y-m-d H:i:s', $v['pay_time']);
  531. $v['add_time'] = date('Y-m-d H:i:s', $v['add_time']);
  532. $v['overdue_time'] = date('Y-m-d H:i:s', $v['overdue_time']);
  533. switch ($v['pay_type']) {
  534. case "yue" :
  535. $v['pay_type'] = "余额";
  536. break;
  537. case "weixin" :
  538. $v['pay_type'] = "微信";
  539. break;
  540. case "alipay" :
  541. $v['pay_type'] = "支付宝";
  542. break;
  543. case 'allinpay':
  544. $v['pay_type'] = "通联支付";
  545. break;
  546. case "admin" :
  547. $v['pay_type'] = "后台赠送";
  548. break;
  549. }
  550. if ($v['type'] == 0) $v['pay_type'] = "免费领取";
  551. if ($v['type'] == 2) {
  552. $v['pay_type'] = "卡密领取";
  553. $v['member_type'] = "卡密激活";
  554. }
  555. if ($v['type'] == 1 && $v['is_free'] == 1) $v['pay_type'] = "免费领取";
  556. $v['user']['overdue_time'] = date('Y-m-d', $v['user']['overdue_time']) == "1970-01-01" ? "" : date('Y-m-d H:i:s', $v['user']['overdue_time']);
  557. }
  558. }
  559. $count = $this->dao->count($where);
  560. return compact('list', 'count');
  561. }
  562. }