PayDetailController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. <?php
  2. namespace app\admin\controller\order;
  3. use app\admin\controller\notify\RechargeController;
  4. use app\admin\service\member\MemberService;
  5. use app\controller\Curd;
  6. use app\model\Goods;
  7. use app\model\GoodsSku;
  8. use app\model\Member;
  9. use app\model\MemberAccount;
  10. use app\model\Order;
  11. use app\model\OrderSheet;
  12. use app\model\PayDetail;
  13. use support\Db;
  14. use support\exception\BusinessException;
  15. use support\Request;
  16. use support\Response;
  17. use Webman\Event\Event;
  18. use function PHPSTORM_META\type;
  19. class PayDetailController extends Curd
  20. {
  21. public function __construct()
  22. {
  23. $this->model = new PayDetail();
  24. }
  25. public function select(Request $request): Response
  26. {
  27. [$where, $format, $limit, $field, $order] = $this->selectInput($request);
  28. $order = $request->get('order', 'desc');
  29. $field = $field ?? 'pay_addtimes';
  30. // $where['pay_status'] = 'SUCCESS';
  31. if ($where['pay_category'] == 'OTHER') {
  32. $where['pay_status'] = 'SUCCESS';
  33. $where['pay_category'] = ['<>', 'RECHARGE'];
  34. } elseif ($where['pay_category'] == 'RECHARGE') {
  35. $where['pay_category'] = ['in', ['RECHARGE', 'VIP']];
  36. }
  37. if (!empty($where['pay_addtimes'])) {
  38. $where['pay_addtimes'][0] = !empty($where['pay_addtimes'][0]) ? strtotime($where['pay_addtimes'][0]) : '';
  39. $where['pay_addtimes'][1] = !empty($where['pay_addtimes'][1]) ? strtotime($where['pay_addtimes'][1]) : '';
  40. }
  41. if (!empty($request->get('premises_id'))) {
  42. $payIds = PayDetail::whereJsonContains('pay_extend_json->remark->premises_id', intval($request->get('premises_id')))
  43. ->pluck('pay_id')
  44. ->toArray();
  45. $where['pay_id'] = '';
  46. if (!empty($payIds)) {
  47. $where['pay_id'] = ['in', $payIds];
  48. }
  49. }
  50. // else if ($where['pay_category'] == 'RECHARGE') {
  51. // $where['pay_status'] = 'SUCCESS';
  52. // $where['pay_category'] = 'RECHARGE';
  53. // $where['pay_prepayid'] = ['in','WXPAY,ALIPAY'];
  54. // }
  55. $query = $this->doSelect($where, $field, $order, $request->get());
  56. return $this->doFormat($query, $format, $limit);
  57. }
  58. protected function doSelect(array $where, string $field = null, string $order = 'desc', $params = [])
  59. {
  60. $model = $this->model->with(['member', 'cert', 'memberAccount']);
  61. foreach ($where as $column => $value) {
  62. if (is_array($value)) {
  63. if ($value[0] === 'like' || $value[0] === 'not like') {
  64. $model = $model->where($column, $value[0], "%$value[1]%");
  65. } elseif (in_array($value[0], ['>', '=', '<', '<>'])) {
  66. $model = $model->where($column, $value[0], $value[1]);
  67. } elseif ($value[0] == 'in' && !empty($value[1])) {
  68. $valArr = $value[1];
  69. if (is_string($value[1])) {
  70. $valArr = explode(",", trim($value[1]));
  71. }
  72. $model = $model->whereIn($column, $valArr);
  73. } elseif ($value[0] == 'not in' && !empty($value[1])) {
  74. $valArr = $value[1];
  75. if (is_string($value[1])) {
  76. $valArr = explode(",", trim($value[1]));
  77. }
  78. $model = $model->whereNotIn($column, $valArr);
  79. } elseif ($value[0] == 'null') {
  80. $model = $model->whereNull($column);
  81. } elseif ($value[0] == 'not null') {
  82. $model = $model->whereNotNull($column);
  83. } elseif ($value[0] !== '' || $value[1] !== '') {
  84. $model = $model->whereBetween($column, $value);
  85. }
  86. } else {
  87. $model = $model->where($column, $value);
  88. }
  89. }
  90. if (empty($params['type'])) {
  91. $model = $model->where(function ($query) {
  92. $query->whereIn('pay_prepayid', ['ALIPAY', 'WXPAY', 'OFFLINE', 'OFFLINE_WXPAY', 'OFFLINE_ALIPAY', 'MONEY'])
  93. ->orWhere('pay_prepayid', 'like', '%CASH%')
  94. ->orWhere('pay_prepayid', 'like', '%WELFARE%');
  95. });
  96. } else {
  97. if ($params['type'] == 'NORMAL') {
  98. $model = $model->where(function ($query) {
  99. $query->whereIn('pay_prepayid', ['ALIPAY', 'WXPAY', 'OFFLINE_WXPAY', 'OFFLINE_ALIPAY', 'MONEY'])
  100. ->orWhere('pay_prepayid', 'like', '%CASH%');
  101. });
  102. } else if ($params['type'] == 'VIP') {
  103. $model = $model->where(function ($query) {
  104. $query->orWhere('pay_category', 'VIP');
  105. });
  106. } else {
  107. $model = $model->where(function ($query) {
  108. $query->orWhere('pay_prepayid', 'like', '%WELFARE%');
  109. });
  110. }
  111. }
  112. if (!empty($params['order_type'])) {
  113. if ($params['order_type'] == 'COMBINE') {
  114. $model = $model->where('join_pay_order_id', 'COMBINE');
  115. } elseif ($params['order_type'] == 'PARTNER') {
  116. $model = $model->where('join_pay_order_id', 'PARTNER');
  117. } elseif ($params['order_type'] == 'VIP') {
  118. $model = $model->where('pay_category', 'VIP');
  119. } elseif ($params['order_type'] == 'RECHARGE') {
  120. $model = $model->where('join_pay_order_id', '<>', 'PARTNER')
  121. ->where('join_pay_order_id', '<>', 'COMBINE')
  122. ->where('pay_category', '<>', 'VIP');
  123. }
  124. }
  125. if ($field) {
  126. $model = $model->orderBy($field, $order);
  127. }
  128. return $model;
  129. }
  130. public function selectWelfare(Request $request): Response
  131. {
  132. [$where, $format, $limit, $field, $order] = $this->selectInput($request);
  133. $order = $request->get('order', 'desc');
  134. $field = $field ?? 'pay_addtimes';
  135. // $where['pay_status'] = 'SUCCESS';
  136. if ($where['pay_category'] == 'OTHER') {
  137. $where['pay_status'] = 'SUCCESS';
  138. $where['pay_category'] = ['<>', 'RECHARGE'];
  139. }
  140. // else if ($where['pay_category'] == 'RECHARGE') {
  141. // $where['pay_status'] = 'SUCCESS';
  142. // $where['pay_category'] = 'RECHARGE';
  143. // $where['pay_prepayid'] = ['in','WXPAY,ALIPAY'];
  144. // }
  145. $query = $this->doSelectWelfare($where, $field, $order);
  146. return $this->doFormat($query, $format, $limit);
  147. }
  148. protected function doSelectWelfare(array $where, string $field = null, string $order = 'desc')
  149. {
  150. $model = $this->model->with(['member', 'cert', 'memberAccount']);
  151. foreach ($where as $column => $value) {
  152. if (is_array($value)) {
  153. if ($value[0] === 'like' || $value[0] === 'not like') {
  154. $model = $model->where($column, $value[0], "%$value[1]%");
  155. } elseif (in_array($value[0], ['>', '=', '<', '<>'])) {
  156. $model = $model->where($column, $value[0], $value[1]);
  157. } elseif ($value[0] == 'in' && !empty($value[1])) {
  158. $valArr = $value[1];
  159. if (is_string($value[1])) {
  160. $valArr = explode(",", trim($value[1]));
  161. }
  162. $model = $model->whereIn($column, $valArr);
  163. } elseif ($value[0] == 'not in' && !empty($value[1])) {
  164. $valArr = $value[1];
  165. if (is_string($value[1])) {
  166. $valArr = explode(",", trim($value[1]));
  167. }
  168. $model = $model->whereNotIn($column, $valArr);
  169. } elseif ($value[0] == 'null') {
  170. $model = $model->whereNull($column);
  171. } elseif ($value[0] == 'not null') {
  172. $model = $model->whereNotNull($column);
  173. } elseif ($value[0] !== '' || $value[1] !== '') {
  174. $model = $model->whereBetween($column, $value);
  175. }
  176. } else {
  177. $model = $model->where($column, $value);
  178. }
  179. }
  180. $model = $model->where(function ($query) {
  181. $query->Where('pay_prepayid', 'like', '%WELFARE%');
  182. });
  183. if ($field) {
  184. $model = $model->orderBy($field, $order);
  185. }
  186. return $model;
  187. }
  188. public function afterQuery($items)
  189. {
  190. foreach ($items as &$item) {
  191. $prepayId = explode('-', $item->pay_prepayid);
  192. $item->order_classify = $item->pay_category;
  193. if (count($prepayId) > 1) {
  194. $item->pay_prepayid = $prepayId[1];
  195. }
  196. $item->type = 'NORMAL';
  197. if (isset($prepayId[1]) && $prepayId[1] == 'WELFARE') {
  198. $item->type = 'WELFARE';
  199. } else if ($item->pay_category == 'VIP') {
  200. $item->type = 'VIP';
  201. }
  202. $memberAccount = [];
  203. if (!empty($item->memberAccount)) {
  204. foreach ($item->memberAccount as $account) {
  205. $memberAccount[strtolower($account->member_account_classify)] = $account;
  206. }
  207. $item->memberAccount = $memberAccount;
  208. }
  209. if (!empty($item->pay_extend_json)) {
  210. $payExtendJson = json_decode($item->pay_extend_json, true);
  211. if (isset($payExtendJson['remark'])) {
  212. $item->service = $payExtendJson['remark']['service'] ?? '';
  213. $item->business = $payExtendJson['remark']['business'] ?? '';
  214. $item->premises_id = $payExtendJson['remark']['premises_id'] ?? '';
  215. $item->premises_name = $payExtendJson['remark']['premises_name'] ?? '';
  216. }
  217. }
  218. $item->to_account_amount = $item->pay_amount;
  219. if (in_array($item['join_pay_order_id'], ['COMBINE', 'PARTNER']) && !empty($item->join_pay_object_json)) {
  220. $item->order_classify = $item['join_pay_order_id'];
  221. $payObjectJson = json_decode($item->join_pay_object_json, true);
  222. if (isset($payObjectJson['recharge_order_id'])) {
  223. $payDetails = PayDetail::whereJsonContains('join_pay_object_json->order_id', $payObjectJson['recharge_order_id'])
  224. ->where('pay_status', 'SUCCESS')
  225. ->get()
  226. ->toArray();
  227. if (count($payDetails) > 1) {
  228. $item->pay_prepayid = 'BY_STAGES';
  229. } else if (count($payDetails) == 1) {
  230. $item->pay_prepayid = $payDetails[0]['pay_prepayid'];
  231. }
  232. $item->pay_amount = PayDetail::whereJsonContains('join_pay_object_json->order_id', $payObjectJson['recharge_order_id'])
  233. ->where('pay_status', 'SUCCESS')
  234. ->sum('pay_amount');
  235. $orderStatus = OrderSheet::where('join_sheet_order_id', $payObjectJson['recharge_order_id'])->value('order_sheet_status');
  236. if ($orderStatus == 'BEING') {
  237. $item->pay_status = 'BEING';
  238. }
  239. }
  240. // $payDetail = PayDetail::where('join_pay_member_id', $item->join_pay_member_id)
  241. // ->where('pay_category', $item['join_pay_order_id'])
  242. // ->select('pay_amount', 'join_pay_object_json')
  243. // ->first();
  244. // $item->pay_amount = $payDetail->pay_amount ?? 0;
  245. // if (!empty($payDetail->join_pay_object_json)) {
  246. // $payObjectJson = json_decode($payDetail->join_pay_object_json, true);
  247. // if (isset($payObjectJson['order_id'])) {
  248. // $orderStatus = OrderSheet::where('join_sheet_order_id', $payObjectJson['order_id'])->value('order_sheet_status');
  249. // if ($orderStatus == 'BEING') {
  250. // $item->pay_status = 'BEING';
  251. // }
  252. // }
  253. // }
  254. }
  255. if ($item->pay_category == 'VIP') {
  256. $payObjectJson = json_decode($item->join_pay_object_json, true);
  257. if (isset($payObjectJson['order_id'])) {
  258. $orderStatus = OrderSheet::where('join_sheet_order_id', $payObjectJson['order_id'])->value('order_sheet_status');
  259. if ($orderStatus == 'BEING') {
  260. $item->pay_status = 'BEING';
  261. }
  262. }
  263. }
  264. }
  265. return $items;
  266. }
  267. /**
  268. * @Desc 产品订单
  269. * @Author Gorden
  270. * @Date 2024/6/5 10:10
  271. *
  272. * @param Request $request
  273. * @return Response
  274. */
  275. public function goodsOrder(Request $request)
  276. {
  277. $orderId = $request->get('order_id', '');
  278. $memberId = $request->get('member_id', '');
  279. if (!$orderId || !$memberId) {
  280. return json_fail('参数异常');
  281. }
  282. $orderSheet = OrderSheet::with([
  283. 'order' => function ($query) {
  284. $query->select('order_id', 'order_amount_total', 'order_amount_pay', 'order_is_complete', 'order_category', 'order_status_system', 'order_status_payment', 'order_status_storage', 'order_addtimes');
  285. },
  286. 'goods' => function ($query) {
  287. $query->select('goods_id', 'goods_name', 'goods_status', 'goods_market_price', 'goods_sales_price', 'goods_addtimes');
  288. },
  289. 'sku' => function ($query) {
  290. $query->select('goods_sku_id', 'goods_sku_specs_json', 'goods_sku_market_price', 'goods_sku_sales_price');
  291. }
  292. ])->where('join_sheet_order_id', $orderId)
  293. ->get()
  294. ->toArray();
  295. $member = Member::with([
  296. 'cert' => function ($query) {
  297. $query->select('join_cert_member_id', 'member_cert_name');
  298. },
  299. 'info' => function ($query) {
  300. $query->select('join_info_member_id', 'member_info_nickname', 'member_info_headimg');
  301. }
  302. ])->where('member_id', $memberId)
  303. ->select('member_id', 'member_mobile', 'join_member_role_id', 'member_is_owner', 'member_is_vip', 'member_is_partner', 'member_is_referrer')
  304. ->first();
  305. if (!$member){
  306. return json_fail('数据异常');
  307. }
  308. $member = $member->toArray();
  309. $certName = $member['cert']['member_cert_name'] ?? '';
  310. $nickname = $member['info']['member_info_nickname'] ?? '';
  311. $mobile = $member['member_mobile'] ?? '';
  312. $member['member_name'] = MemberService::getMemberCertName($mobile, $certName, $nickname);
  313. $member['info']['member_info_headimg'] = MemberService::getAvatarUrl($member['info']['member_info_headimg'] ?? '');
  314. $member['level'] = MemberService::getRoleName($member['join_member_role_id']);
  315. $payDetails = PayDetail::whereJsonContains('join_pay_object_json->order_id', $orderId)
  316. ->where('pay_status', 'SUCCESS')
  317. ->select('pay_status', 'pay_amount', 'pay_paytimes', 'pay_prepayid')
  318. ->get();
  319. $data = [
  320. 'payDetails' => $payDetails,
  321. 'goodsOrder' => $orderSheet,
  322. 'member' => $member
  323. ];
  324. return json_success('', $data);
  325. }
  326. /**
  327. * 余额账户充值
  328. */
  329. public function insertRecharge(Request $request): Response
  330. {
  331. if ($this->validate && !$this->validateClass->scene('add')->check($request->post())) {
  332. return json_fail($this->validateClass->getError());
  333. }
  334. $password = $request->post('recharge_password', '');
  335. if (!$password || $password != '123456') {
  336. return json_fail('充值密码错误');
  337. }
  338. Db::beginTransaction();
  339. try {
  340. $data = $this->insertRechargeInput($request);
  341. $data['pay_prepayid'] = $request->post('pay_prepayid', '');
  342. unset($data['orderId']);
  343. $payDetailId = $this->doInsert($data);
  344. (new RechargeController)->disposePaySuccess($payDetailId);
  345. Db::commit();
  346. } catch (BusinessException $customException) {
  347. Db::rollBack();
  348. return json_fail($customException->getMessage());
  349. } catch (\Exception $e) {
  350. Db::rollBack();
  351. dump($e->getMessage());
  352. return json_fail('数据写入失败11');
  353. }
  354. return json_success('success');
  355. }
  356. /**
  357. * 余额账户赠送
  358. */
  359. public function insertGive(Request $request): Response
  360. {
  361. if ($this->validate && !$this->validateClass->scene('add')->check($request->post())) {
  362. return json_fail($this->validateClass->getError());
  363. }
  364. $password = $request->post('recharge_password', '');
  365. if (!$password || $password != '123456') {
  366. return json_fail('赠送密码错误');
  367. }
  368. Db::beginTransaction();
  369. try {
  370. $data = $this->insertGiveInput($request);
  371. $data['pay_prepayid'] = $data['join_pay_member_id'] . '-CASH';
  372. // 金额累加到福利账户
  373. $memberAccount = MemberAccount::where('join_account_member_id', $data['join_pay_member_id'])->where('member_account_classify', 'CASH')->first();
  374. $memberAccount->member_account_income = $memberAccount->member_account_income + $data['pay_amount'];
  375. $memberAccount->member_account_surplus = $memberAccount->member_account_surplus + $data['pay_amount'];
  376. $memberAccount->save();
  377. $data['pay_amount'] = 0;
  378. $this->doInsert($data);
  379. Db::commit();
  380. } catch (BusinessException $customException) {
  381. Db::rollBack();
  382. return json_fail($customException->getMessage());
  383. } catch (\Exception $e) {
  384. Db::rollBack();
  385. dump($e->getMessage());
  386. return json_fail('数据写入失败11');
  387. }
  388. return json_success('success');
  389. }
  390. /**
  391. * 福利账户充值
  392. */
  393. public function insertRechargeWelfare(Request $request): Response
  394. {
  395. if ($this->validate && !$this->validateClass->scene('add')->check($request->post())) {
  396. return json_fail($this->validateClass->getError());
  397. }
  398. $password = $request->post('recharge_password', '');
  399. if (!$password || $password != '123456') {
  400. return json_fail('充值密码错误');
  401. }
  402. Db::beginTransaction();
  403. try {
  404. $data = $this->insertRechargeInput($request, 'WELFARE');
  405. $orderId = $data['orderId'];
  406. unset($data['orderId']);
  407. $data['pay_prepayid'] = $data['join_pay_member_id'] . '-WELFARE';
  408. $memberAccount = MemberAccount::where('join_account_member_id', $data['join_pay_member_id'])
  409. ->where('member_account_classify', 'WELFARE')
  410. ->first();
  411. if ($memberAccount->member_account_status != 'ACTIVED') {
  412. throw new BusinessException('福利账户未开启');
  413. }
  414. $this->doInsert($data);
  415. // 金额累加到福利账户
  416. $memberAccount->member_account_income = $memberAccount->member_account_income + $data['pay_amount'];
  417. $memberAccount->member_account_surplus = $memberAccount->member_account_surplus + $data['pay_amount'];
  418. $memberAccount->save();
  419. Db::commit();
  420. // 入收支明细表
  421. $params['orderId'] = $orderId;
  422. $params['inout_category'] = '会员充值订单收入';
  423. Event::dispatch('statistics.inout.in', $params);
  424. } catch (BusinessException $customException) {
  425. Db::rollBack();
  426. return json_fail($customException->getMessage());
  427. } catch (\Exception $e) {
  428. Db::rollBack();
  429. dump($e->getMessage());
  430. return json_fail('数据写入失败11');
  431. }
  432. return json_success('success');
  433. }
  434. /**
  435. * @Desc
  436. * @Author Gorden
  437. * @Date 2024/6/5 13:39
  438. *
  439. * @param Request $request
  440. * @return array
  441. * @throws BusinessException
  442. */
  443. protected function insertRechargeInput(Request $request, $type = "CASH"): array
  444. {
  445. $params = $request->post();
  446. $data = $this->inputFilter($params);
  447. $goods = Goods::find($params['goods_id']);
  448. $extendJson = [];
  449. // if (!$params['is_custom']) {
  450. // Db::beginTransaction();
  451. try {
  452. if (!$params['is_custom']) {
  453. $data['pay_amount'] = $goods->goods_sales_price;
  454. }
  455. $orderId = "OD" . date('ymdHi') . random_string(4, 'up');
  456. $orderGroupId = "OD" . date('ymdHi') . random_string(4, 'up');
  457. $orderData = [
  458. 'order_id' => $orderId,
  459. 'order_groupby' => $orderGroupId,
  460. 'join_order_member_id' => $data['join_pay_member_id'],
  461. 'order_name' => date('Y-m-d H:i:s') . '-订单',
  462. 'order_amount_total' => $data['pay_amount'],
  463. 'order_amount_pay' => $data['pay_amount'],
  464. 'order_amount_json' => '{"tax": 0, "freight": 0}',
  465. 'order_status_payment' => 'SUCCESS',
  466. 'order_classify' => 'RECHARGE',
  467. 'order_category' => 'RECHARGE',
  468. 'order_status_system' => 'PAYING',
  469. 'order_status_storage' => 'PENDING',
  470. 'order_addtimes' => time()
  471. ];
  472. if ($type == 'WELFARE') {
  473. $orderData['order_is_complete'] = 'Y';
  474. $orderData['order_status_system'] = 'DONE';
  475. $orderData['order_status_storage'] = 'DONE';
  476. }
  477. $sku = GoodsSku::where('join_sku_goods_id', $params['goods_id'])->first();
  478. Order::insert($orderData);
  479. $orderSheetData = [
  480. 'join_sheet_member_id' => $data['join_pay_member_id'],
  481. 'join_sheet_order_id' => $orderId,
  482. 'join_sheet_goods_id' => $params['goods_id'],
  483. 'join_sheet_goods_sku_id' => $sku ? $sku->goods_sku_id : 0,
  484. 'order_sheet_status' => 'DONE',
  485. 'order_sheet_category' => 'RECHARGE',
  486. 'order_sheet_num' => 1,
  487. 'order_sheet_price' => $data['pay_amount'],
  488. 'order_sheet_amount' => $data['pay_amount'],
  489. 'order_sheet_pay' => $data['pay_amount'],
  490. 'order_sheet_addtimes' => time()
  491. ];
  492. OrderSheet::insert($orderSheetData);
  493. // Db::commit();
  494. } catch (\Exception $e) {
  495. // Db::rollBack();
  496. throw new BusinessException("数据错误");
  497. }
  498. $data['orderId'] = $orderId;
  499. $data['join_pay_order_id'] = $orderGroupId;
  500. $data['join_pay_object_json'] = json_encode(['order_id' => $orderId]);
  501. $rate = 0;
  502. if (!empty($goods->goods_attribute_json) && $type == "CASH") {
  503. $attributeJson = json_decode($goods->goods_attribute_json, true);
  504. if (isset($attributeJson['added'])) {
  505. $rate = $attributeJson['added'] ? $attributeJson['added']['nbr'] : 0;
  506. }
  507. }
  508. $extendJson['added_amount'] = number_format($data['pay_amount'] * $rate, 2, '.', '');
  509. $extendJson['added_rate'] = $rate;
  510. // } else {
  511. // // $extendJson['notify'] = 'success';
  512. // $extendJson['is_custom'] = $params['is_custom'];
  513. // }
  514. $data['pay_extend_json'] = json_encode($extendJson);
  515. $data['pay_paytimes'] = date('Y-m-d H:i:s', strtotime($data['pay_paytimes']));
  516. $data['pay_prepayid'] = 0;
  517. return $data;
  518. }
  519. /**
  520. * @Desc
  521. * @Author Gorden
  522. * @Date 2024/6/5 13:39
  523. *
  524. * @param Request $request
  525. * @return array
  526. * @throws BusinessException
  527. */
  528. protected function insertGiveInput(Request $request, $type = "CASH"): array
  529. {
  530. $params = $request->post();
  531. $data = $this->inputFilter($params);
  532. $goods = Goods::find($params['goods_id']);
  533. $extendJson = [];
  534. // if (!$params['is_custom']) {
  535. Db::beginTransaction();
  536. try {
  537. if (!$params['is_custom']) {
  538. $data['pay_amount'] = $goods->goods_sales_price;
  539. }
  540. // $orderId = "OD" . date('ymdHi') . random_string(4, 'up');
  541. // $orderGroupId = "OD" . date('ymdHi') . random_string(4, 'up');
  542. // $orderData = [
  543. // 'order_id' => $orderId,
  544. // 'order_groupby' => $orderGroupId,
  545. // 'join_order_member_id' => $data['join_pay_member_id'],
  546. // 'order_name' => date('Y-m-d H:i:s') . '-订单',
  547. // 'order_amount_total' => $data['pay_amount'],
  548. // 'order_amount_pay' => $data['pay_amount'],
  549. // 'order_amount_json' => '{"tax": 0, "freight": 0}',
  550. // 'order_status_payment' => 'SUCCESS',
  551. // 'order_classify' => 'RECHARGE',
  552. // 'order_category' => 'RECHARGE',
  553. // 'order_status_system' => 'PAYING',
  554. // 'order_status_storage' => 'PENDING',
  555. // 'order_addtimes' => time()
  556. // ];
  557. // if ($type == 'WELFARE') {
  558. // $orderData['order_is_complete'] = 'Y';
  559. // $orderData['order_status_system'] = 'DONE';
  560. // $orderData['order_status_storage'] = 'DONE';
  561. // }
  562. // $sku = GoodsSku::where('join_sku_goods_id', $params['goods_id'])->first();
  563. //
  564. // Order::insert($orderData);
  565. // $orderSheetData = [
  566. // 'join_sheet_member_id' => $data['join_pay_member_id'],
  567. // 'join_sheet_order_id' => $orderId,
  568. // 'join_sheet_goods_id' => $params['goods_id'],
  569. // 'join_sheet_goods_sku_id' => $sku ? $sku->goods_sku_id : 0,
  570. // 'order_sheet_status' => 'DONE',
  571. // 'order_sheet_category' => 'RECHARGE',
  572. // 'order_sheet_num' => 1,
  573. // 'order_sheet_price' => $data['pay_amount'],
  574. // 'order_sheet_amount' => $data['pay_amount'],
  575. // 'order_sheet_pay' => $data['pay_amount'],
  576. // 'order_sheet_addtimes' => time()
  577. // ];
  578. //
  579. // OrderSheet::insert($orderSheetData);
  580. Db::commit();
  581. } catch (\Exception $e) {
  582. dump($e->getMessage());
  583. Db::rollBack();
  584. throw new BusinessException("数据错误");
  585. }
  586. $data['join_pay_order_id'] = "SYSTEM";
  587. $data['join_pay_object_json'] = json_encode(['order_id' => 'SYSTEM']);
  588. $rate = 0;
  589. $extendJson['added_amount'] = $data['pay_amount'];
  590. $extendJson['added_rate'] = $rate;
  591. $data['pay_extend_json'] = json_encode($extendJson);
  592. $data['pay_paytimes'] = date('Y-m-d H:i:s', strtotime($data['pay_paytimes']));
  593. $data['pay_prepayid'] = 0;
  594. return $data;
  595. }
  596. /**
  597. * @Desc 加备注-门店、服务人员、业务人员
  598. * @Author Gorden
  599. * @Date 2024/8/29 16:14
  600. *
  601. * @param Request $request
  602. * @return Response
  603. */
  604. public function remark(Request $request)
  605. {
  606. $payId = $request->post('pay_id', '');
  607. if (!$payId) {
  608. return json_fail('参数异常');
  609. }
  610. $payDetail = PayDetail::where('pay_id', $payId)->first();
  611. if (!$payDetail) {
  612. return json_fail("数据异常");
  613. }
  614. try {
  615. $data = [
  616. 'premises_id' => $request->post('premises_id', ''),
  617. 'premises_name' => $request->post('premises_name', ''),
  618. 'business' => $request->post('business', ''),
  619. 'service' => $request->post('service', '')
  620. ];
  621. $payExtendJson = [];
  622. if (!empty($payDetail->pay_extend_json)) {
  623. $payExtendJson = json_decode($payDetail->pay_extend_json, true);
  624. }
  625. $payExtendJson['remark'] = $data;
  626. $payDetail->pay_extend_json = json_encode($payExtendJson, JSON_UNESCAPED_UNICODE);
  627. $payDetail->save();
  628. return json_success('success');
  629. } catch (\Exception $e) {
  630. return json_fail('备注保存失败');
  631. }
  632. }
  633. }