OrdersController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. <?php
  2. namespace App\Http\Controllers\QuickApp\Order;
  3. use App\Http\Controllers\QuickApp\BaseController;
  4. use Illuminate\Http\Request;
  5. use App\Modules\Subscribe\Services\BookOrderService;
  6. use App\Modules\Subscribe\Services\ChapterOrderService;
  7. use App\Modules\Xcx\Services\XcxOrderService as OrderService;
  8. use App\Http\Controllers\QuickApp\Order\Transformers\BookOrderTransformer;
  9. use App\Http\Controllers\QuickApp\Order\Transformers\ChapterOrderTransformer;
  10. use App\Http\Controllers\QuickApp\Order\Transformers\ChargeListTransformer;
  11. use App\Modules\Subscribe\Services\YearOrderService;
  12. use App\Modules\User\Services\UserService;
  13. use DB;
  14. use Redis;
  15. use Hashids;
  16. use EasyWeChat\Foundation\Application;
  17. use EasyWeChat\Payment\Order as Wxorder;
  18. use App\Modules\Product\Services\ProductService;
  19. use App\Modules\Book\Services\BookConfigService;
  20. use Log;
  21. class OrdersController extends BaseController
  22. {
  23. /**
  24. * @apiDefine Order 订单
  25. */
  26. /**
  27. * @apiVersion 1.0.0
  28. * @apiDescription 充值列表
  29. * @api {get} order/chargeList 充值列表
  30. * @apiParam {String} [token] token
  31. * @apiHeader {String} [Authorization] token 两个token任选其一
  32. * @apiGroup Order
  33. * @apiName chargeList
  34. * @apiSuccess {int} code 状态码
  35. * @apiSuccess {String} msg 信息
  36. * @apiSuccess {object} data 结果集
  37. * @apiSuccessExample {json} Success-Response:
  38. * HTTP/1.1 200 OK
  39. * {
  40. * code: 0,
  41. * msg: "",
  42. * data: [
  43. * {
  44. * product_id: 1,
  45. * price: "30.00元",
  46. * vip: 0,
  47. * intro: [
  48. * {
  49. * label: 3000,
  50. * important: false
  51. * },
  52. * {
  53. * label: "书币",
  54. * important: true
  55. * }
  56. * ]
  57. * },
  58. * {
  59. * product_id: 2,
  60. * price: "50.00元",
  61. * vip: 1,
  62. * intro: [
  63. * {
  64. * label: 5000,
  65. * important: false
  66. * },
  67. * {
  68. * label: "1000+",
  69. * important: true
  70. * },
  71. * {
  72. * label: "书币",
  73. * important: false
  74. * }
  75. * ]
  76. * },
  77. * {
  78. * product_id: 5,
  79. * price: "365.00元",
  80. * vip: 0,
  81. * intro: [
  82. * {
  83. * label: "年费VIP会员",
  84. * important: true
  85. * }
  86. * ]
  87. * }
  88. * ]
  89. * }
  90. */
  91. public function chargeList(Request $request)
  92. {
  93. $res = ProductService::getChargeProduct();
  94. if (!$res->isEmpty()) {
  95. $data = [];
  96. foreach ($res as $v) {
  97. $intro = [];
  98. if ($v->given > 0 && $v->type == 'TICKET_RECHARGE') {
  99. $intro = [
  100. [
  101. 'label' => ($v->price * 100) . "+",
  102. 'important' => false,
  103. ],
  104. [
  105. 'label' => $v->given,
  106. 'important' => true,
  107. ],
  108. [
  109. 'label' => '书币',
  110. 'important' => false,
  111. ]
  112. ];
  113. $intro2 = [
  114. ['label' => '多送', 'important' => false],
  115. ['label' => (int) ($v->given / 100), 'important' => true],
  116. ['label' => '元', 'important' => false],
  117. ];
  118. $v->vip = 0;
  119. }
  120. if ($v->given == 0 && $v->type == 'TICKET_RECHARGE') {
  121. $intro = [
  122. [
  123. 'label' => $v->price * 100,
  124. 'important' => false,
  125. ],
  126. [
  127. 'label' => '书币',
  128. 'important' => false,
  129. ]
  130. ];
  131. $v->vip = 0;
  132. $intro2 = [];
  133. }
  134. if ($v->given == 0 && $v->type == 'YEAR_ORDER') {
  135. $intro = [
  136. [
  137. 'label' => '年费VIP会员',
  138. 'important' => true,
  139. ]
  140. ];
  141. $v->vip = 1;
  142. $intro2 = [
  143. ['label' => '每天1元,全年免费看', 'important' => false],
  144. ];
  145. }
  146. $data[] = [
  147. 'product_id' => $v->id,
  148. 'price' => (int) $v->price . '元',
  149. 'vip' => $v->vip,
  150. 'intro' => $intro,
  151. 'intro2' => $intro2,
  152. 'is_default' => $v->is_default,
  153. ];
  154. }
  155. return response()->success($data);
  156. } else {
  157. return response()->error('QAPP_SYS_ERROR');
  158. }
  159. }
  160. /**
  161. * @apiVersion 1.0.0
  162. * @apiDescription 单本消费记录
  163. * @api {get} order/bookOrderList 单本消费记录
  164. * @apiParam {String} [token] token
  165. * @apiHeader {String} [Authorization] token 两个token任选其一
  166. * @apiGroup Order
  167. * @apiName bookOrderList
  168. * @apiSuccess {int} code 状态码
  169. * @apiSuccess {String} msg 信息
  170. * @apiSuccess {object} data 结果集
  171. * @apiSuccess {Int} uid uid
  172. * @apiSuccess {Int} bid bid
  173. * @apiSuccess {Int} book_name 书名
  174. * @apiSuccess {Int} fee 钱
  175. * @apiSuccess {String} created_at 时间
  176. * @apiSuccessExample {json} Success-Response:
  177. * HTTP/1.1 200 OK
  178. * {
  179. * code: 0,
  180. * msg: "",
  181. * data: list:[
  182. * {
  183. * uid: 4,
  184. * bid: 1,
  185. * book_name: "dfsedfertrwet",
  186. * fee: 100,
  187. * created_at: "2017-12-02 16:24:54"
  188. * }
  189. * ]
  190. * meta: {
  191. * total: 1,
  192. * per_page: 15,
  193. * current_page: 1,
  194. * last_page: 1,
  195. * next_page_url: "",
  196. * prev_page_url: ""
  197. * }
  198. * }
  199. */
  200. public function bookOrderList(Request $request)
  201. {
  202. $page_size = $request->input('page_size', 15);
  203. $book_order = BookOrderService::getRecord($this->uid, $page_size);
  204. return response()->pagination(new BookOrderTransformer(), $book_order);
  205. }
  206. /**
  207. * @apiVersion 1.0.0
  208. * @apiDescription 章节消费记录
  209. * @api {get} order/chapterOrderList 章节消费记录
  210. * @apiParam {String} [token] token
  211. * @apiHeader {String} [Authorization] token 两个token任选其一
  212. * @apiGroup Order
  213. * @apiName chapterOrderList
  214. * @apiSuccess {int} code 状态码
  215. * @apiSuccess {String} msg 信息
  216. * @apiSuccess {object} data 结果集
  217. * @apiSuccess {Int} uid uid
  218. * @apiSuccess {Int} bid bid
  219. * @apiSuccess {Int} cid cid
  220. * @apiSuccess {Int} chapter_name 章节名
  221. * @apiSuccess {Int} book_name 书名
  222. * @apiSuccess {Int} fee 钱
  223. * @apiSuccess {String} created_at 时间
  224. * @apiSuccessExample {json} Success-Response:
  225. * HTTP/1.1 200 OK
  226. * {
  227. * code: 0,
  228. * msg: "",
  229. * data: list:[
  230. * {
  231. * uid: 4,
  232. * bid: 1,
  233. * cid: 1,
  234. * chapter_name: "sdfsd",
  235. * book_name: "dfsedfertrwet",
  236. * fee: 100,
  237. * created_at: "2017-12-02 16:24:54"
  238. * }
  239. * ]
  240. * meta: {
  241. * total: 1,
  242. * per_page: 15,
  243. * current_page: 1,
  244. * last_page: 1,
  245. * next_page_url: "",
  246. * prev_page_url: ""
  247. * }
  248. * }
  249. */
  250. public function chapterOrderList(Request $request)
  251. {
  252. $chapter_model = new ChapterOrderService();
  253. $page_size = $request->input('page_size', 15);
  254. $chapter_order = $chapter_model->getByUid($this->uid, $page_size);
  255. return response()->pagination(new ChapterOrderTransformer(), $chapter_order);
  256. }
  257. /**
  258. * @apiVersion 1.0.0
  259. * @apiDescription 充值记录
  260. * @api {get} order/chargeRecordLists 充值记录
  261. * @apiParam {String} [token] token
  262. * @apiHeader {String} [Authorization] token 两个token任选其一
  263. * @apiGroup Order
  264. * @apiName chargeRecordLists
  265. * @apiSuccess {int} code 状态码
  266. * @apiSuccess {String} msg 信息
  267. * @apiSuccess {object} data 结果集
  268. * @apiSuccess {String} data.price 价格
  269. * @apiSuccess {String} data.status 状态
  270. * @apiSuccess {String} data.trade_no 订单号
  271. * @apiSuccess {String} data.created_at 时间
  272. * @apiSuccessExample {json} Success-Response:
  273. * HTTP/1.1 200 OK
  274. * {
  275. * code: 0,
  276. * msg: "",
  277. * data: {
  278. * list: [
  279. * {
  280. * id: 134,
  281. * price: "1.00",
  282. * status: "PAID",
  283. * trade_no: "201712021915481585670623626232",
  284. * created_at: "2017-12-02 19:15:56"
  285. * }
  286. * ],
  287. * meta: {
  288. * total: 1,
  289. * per_page: 15,
  290. * current_page: 1,
  291. * last_page: 1,
  292. * next_page_url: "",
  293. * prev_page_url: ""
  294. * }
  295. * }
  296. * }
  297. */
  298. public function chargeRecordLists(Request $request)
  299. {
  300. $page_size = $request->input('page_size', 15);
  301. $res = OrderService::getOrderList($this->uid, $page_size);
  302. return response()->pagination(new ChargeListTransformer(), $res);
  303. }
  304. //订单是否成功
  305. public function isSuccess(Request $request)
  306. {
  307. $order = $request->input('order');
  308. $order_info = OrderService::getByTradeNo($order);
  309. if ($order_info && $order_info->status == 'PAID') {
  310. return response()->success();
  311. }
  312. return response()->error('QAPP_SYS_ERROR');
  313. }
  314. /**
  315. * @apiVersion 1.0.0
  316. * @apiDescription 支付
  317. * @api {get} goToPay 支付
  318. * @apiGroup pay
  319. * @apiName wxindex
  320. * @apiParam {Int} product_id product_id
  321. * @apiParam {String} [token] token
  322. * @apiHeader {String} [Authorization] token 两个token任选其一
  323. * @apiParam {String} bid bid
  324. * @apiParam {String} sign 签名
  325. * @apiSuccess {int} code 状态码
  326. * @apiSuccess {String} msg 信息
  327. * @apiSuccess {Object} data 信息
  328. * @apiSuccess {Object} data.appId 唤起支付的appId
  329. * @apiSuccess {Object} data.package 唤起支付的package
  330. * @apiSuccess {Object} data.nonceStr 唤起支付的nonceStr
  331. * @apiSuccess {Object} data.timeStamp 唤起支付的timeStamp
  332. * @apiSuccess {Object} data.signType 唤起支付的signType
  333. * @apiSuccess {Object} data.paySign 唤起支付sign
  334. * @apiSuccessExample {json} Success-Response:
  335. * HTTP/1.1 200 OK
  336. * {
  337. * code: 0,
  338. * msg: "",
  339. * data: {
  340. *
  341. * }
  342. */
  343. function wxindex(Request $request)
  344. {
  345. $product_id = $request->has('product_id') ? $request->get('product_id') : '';
  346. $sign = $request->has('sign') ? $request->get('sign') : '';
  347. $send_order_id = $request->has('send_order_id') ? $request->get('send_order_id') : 0;
  348. if (empty($product_id) || empty($sign)) {
  349. return response()->error('QAPP_PARAM_ERROR');
  350. }
  351. $bid = $request->has('bid') ? $request->get('bid') : 0;
  352. $openid = $this->openid;
  353. //$openid = 'o0bsX0b3-kgWIb4JBdTAk7HVtnrk';
  354. //根据分校id获取支付配置id
  355. $trade_no = date("YmdHis") . hexdec(uniqid());
  356. $product_info = ProductService::getProductSingle($product_id);
  357. $uid = $this->uid;
  358. $distribution_channel_id = $this->distribution_channel_id;
  359. $price = $product_info->price * 100;
  360. if ($uid < 32) { }
  361. if (in_array($uid, explode(',', env('TEST_UID')))) {
  362. $price = 1;
  363. }
  364. if ($bid) {
  365. try {
  366. $bid = Hashids::decode($bid)[0];
  367. } catch (\Exception $e) {
  368. $bid = 0;
  369. }
  370. }
  371. //$price = 1;
  372. if ($product_info->type == 'YEAR_ORDER') {
  373. $order_type = 'YEAR';
  374. } elseif ($product_info->type == 'BOOK_ORDER') {
  375. $order_type = 'BOOK';
  376. } elseif ($product_info->type == 'TICKET_RECHARGE') {
  377. $order_type = 'RECHARGE';
  378. } else {
  379. $order_type = '';
  380. }
  381. $res = $this->createUnPayOrder([
  382. 'distribution_channel_id' => $distribution_channel_id,
  383. 'uid' => $uid,
  384. 'product_id' => $product_id,
  385. 'price' => $price / 100,
  386. 'pay_type' => 1,
  387. 'trade_no' => $trade_no,
  388. 'pay_merchant_source' => 'XIAOCHENGXU',
  389. 'pay_merchant_id' => 0,
  390. 'create_ip' => $request->getClientIp(),
  391. 'send_order_id' => $send_order_id,
  392. 'order_type' => $order_type,
  393. 'from_bid' => $bid,
  394. 'from_type' => 'QuickApp',
  395. 'activity_id' => 0
  396. ]);
  397. Log::info('order is');
  398. Log::info($res);
  399. //微信下单
  400. $options = [
  401. 'app_id' => 'wxa0c8331eba3b34d5',
  402. 'payment' => [
  403. 'merchant_id' => 1501944981,
  404. 'key' => 'ee245088b93ba88008279d95f6d30413',
  405. ]
  406. ];
  407. $app = new Application($options);
  408. $payment = $app->payment;
  409. $attributes = [
  410. 'trade_type' => 'JSAPI',
  411. 'body' => 'novel read',
  412. 'detail' => 'novel read',
  413. 'out_trade_no' => $trade_no,
  414. 'total_fee' => $price,
  415. 'notify_url' => env('QAPP_PAY_CALL_BACK_URL'),
  416. 'openid' => $openid,
  417. 'spbill_create_ip' => $request->getClientIp(),
  418. ];
  419. $order = new Wxorder($attributes);
  420. Log::info('wexin order--------');
  421. Log::info($order);
  422. $result = $payment->prepare($order);
  423. Log::info('wexin order--xcx--result-----');
  424. Log::info($result);
  425. if ($result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS') {
  426. Log::info('wechat success in');
  427. $data = [
  428. 'appId' => $result->appid,
  429. 'package' => 'prepay_id=' . $result->prepay_id,
  430. 'nonceStr' => $result->nonce_str,
  431. 'timeStamp' => (string) time(),
  432. 'signType' => 'MD5',
  433. ];
  434. $data['paySign'] = $this->MakeSign($data);
  435. unset($data['appId']);
  436. $data['order'] = $trade_no;
  437. $data = [
  438. 'code' => 0,
  439. 'msg' => '',
  440. 'data' => $data
  441. ];
  442. return response()->json(($data));
  443. }
  444. return null;
  445. }
  446. /**
  447. * @apiVersion 1.0.0
  448. * @apiDescription 订单查询
  449. * @api {get} checkOrder 订单查询
  450. * @apiGroup pay
  451. * @apiName checkOrder
  452. * @apiParam {String} [token] token
  453. * @apiHeader {String} [Authorization] token 两个token任选其一
  454. * @apiParam {String} order order
  455. * @apiSuccess {int} code 状态码
  456. * @apiSuccess {String} msg 信息
  457. * @apiSuccess {Object} data 信息
  458. * @apiSuccessExample {json} Success-Response:
  459. * HTTP/1.1 200 OK
  460. * {
  461. * code: 0,
  462. * msg: "",
  463. * data: {
  464. *
  465. * }
  466. */
  467. public function checkOrder(Request $request)
  468. {
  469. $order = $request->input('order', '');
  470. $i = 0;
  471. $uid = $this->uid;
  472. while ($i <= 10) {
  473. $order_info = OrderService::getByTradeNo($order);
  474. if (!$order_info) {
  475. return response()->error('QAPP_SYS_ERROR');
  476. break;
  477. }
  478. if (isset($order_info->status) && $order_info->status == 'PAID') {
  479. $data['balance'] = 0;
  480. $user = UserService::getById($uid);
  481. if ($user) {
  482. $data['balance'] = $user->balance;
  483. }
  484. return response()->success($data);
  485. }
  486. sleep(1);
  487. $i++;
  488. }
  489. return response()->error('QAPP_SYS_ERROR');
  490. }
  491. protected function MakeSign($value)
  492. {
  493. $data = $value;
  494. //签名步骤一:按字典序排序参数
  495. ksort($data);
  496. $buff = "";
  497. foreach ($data as $k => $v) {
  498. if ($k != "sign" && $v != "" && !is_array($v)) {
  499. $buff .= $k . "=" . $v . "&";
  500. }
  501. }
  502. $buff = trim($buff, "&");
  503. //签名步骤二:在string后加入KEY
  504. $string = $buff . "&key=" . 'ee245088b93ba88008279d95f6d30413';
  505. //签名步骤三:MD5加密
  506. $string = md5($string);
  507. //签名步骤四:所有字符转为大写
  508. $result = strtoupper($string);
  509. return $result;
  510. }
  511. /**
  512. * 官方微信回调
  513. * @param Request $request
  514. * @return
  515. */
  516. function wxback_xcx(Request $request)
  517. {
  518. Log::info('-------------en----------------');
  519. $options = [
  520. 'app_id' => 'wxa0c8331eba3b34d5',
  521. 'payment' => [
  522. 'merchant_id' => 1501944981,
  523. 'key' => 'ee245088b93ba88008279d95f6d30413',
  524. ]
  525. ];
  526. $app = new Application($options);
  527. $response = $app->payment->handleNotify(function ($notify, $successful) {
  528. if (!$successful) return 'fail';
  529. $trade_no = $notify->out_trade_no;
  530. $order = OrderService::getByTradeNo($trade_no);
  531. if (!$order) {
  532. return 'fail';
  533. }
  534. if (isset($order->status) && $order->status == 'PAID') {
  535. Log::info('has_pay:' . $trade_no);
  536. return true;
  537. }
  538. DB::beginTransaction();
  539. try {
  540. $transaction_id = $notify->transaction_id;
  541. $uid = $order->uid;
  542. $distribution_channel_id = $order->distribution_channel_id;
  543. $product_id = $order->product_id;
  544. $product = ProductService::getProductSingle($product_id);
  545. $send_order_id = 0;
  546. $price = $product->price;
  547. //$this->updateOrderTotal($trade_no,$transaction_id);
  548. // 更新其他定制Order表
  549. if ($product->type == 'YEAR_ORDER') {
  550. Log::info('YEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDER');
  551. $order_type = 'YEAR';
  552. $this->yearOrder($uid, $distribution_channel_id, $price, $send_order_id);
  553. $order->order_type = $order_type;
  554. $order->status = 'PAID';
  555. $order->pay_end_at = date('Y-m-d H:i:s');
  556. $order->transaction_id = $transaction_id;
  557. $order->save();
  558. } elseif ($product->type == 'BOOK_ORDER') {
  559. Log::info('BOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDER');
  560. $order_type = 'BOOK';
  561. $this->bookOrder($product_id, $uid, $send_order_id, $price, $distribution_channel_id);
  562. $order->order_type = $order_type;
  563. $order->status = 'PAID';
  564. $order->pay_end_at = date('Y-m-d H:i:s');
  565. $order->transaction_id = $transaction_id;
  566. $order->save();
  567. } elseif ($product->type == 'TICKET_RECHARGE') {
  568. Log::info('TICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGE');
  569. $order_type = 'RECHARGE';
  570. $this->userCharge($product, $uid);
  571. $order->order_type = $order_type;
  572. $order->status = 'PAID';
  573. $order->pay_end_at = date('Y-m-d H:i:s');
  574. $order->transaction_id = $transaction_id;
  575. $order->save();
  576. } else {
  577. DB::rollback();
  578. return 'Order not exist.';
  579. }
  580. DB::commit();
  581. return true;
  582. } catch (\Exception $e) {
  583. DB::rollback();
  584. return 'fail';
  585. }
  586. });
  587. return $response;
  588. }
  589. /**
  590. * 单本充值会掉
  591. * @param $product_id
  592. * @param $uid
  593. * @param $send_order_id
  594. * @param $fee
  595. */
  596. private function bookOrder($product_id, $uid, $send_order_id, $fee, $distribution_channel_id)
  597. {
  598. $book_conf = BookConfigService::getBookByProduct($product_id);
  599. $insert_data['bid'] = isset($book_conf->bid) ? $book_conf->bid : '';
  600. $insert_data['book_name'] = isset($book_conf->book_name) ? $book_conf->book_name : '';
  601. $insert_data['uid'] = $uid;
  602. $insert_data['distribution_channel_id'] = $distribution_channel_id;
  603. $insert_data['fee'] = $fee;
  604. $insert_data['send_order_id'] = $send_order_id;
  605. $insert_data['charge_balance'] = 0;
  606. $insert_data['reward_balance'] = 0;
  607. Log::info('start_save_book_order');
  608. Log::info($insert_data);
  609. return BookOrderService::save_book_order($insert_data);
  610. }
  611. /**
  612. * 包年
  613. * @param $uid
  614. * @param $distribution_channel_id
  615. * @param $fee
  616. * @param $send_order_id
  617. * @return mixed
  618. */
  619. private function yearOrder($uid, $distribution_channel_id, $fee, $send_order_id)
  620. {
  621. Log::info('start_save_year_order');
  622. $insert_data['uid'] = $uid;
  623. $insert_data['distribution_channel_id'] = $distribution_channel_id;
  624. $insert_data['fee'] = $fee;
  625. $insert_data['send_order_id'] = $send_order_id;
  626. Log::info($insert_data);
  627. return YearOrderService::save_year_order($insert_data);
  628. }
  629. /**
  630. * 用户充值
  631. * @param $product
  632. * @param $uid\
  633. */
  634. private function userCharge($product, $uid)
  635. {
  636. $total = $product->price * 100 + $product->given;
  637. UserService::addBalance($uid, $total, $product->price * 100, $product->given);
  638. Log::info('update_user_balance_end:' . $uid . ' balance_add:' . $total);
  639. }
  640. /**
  641. * 添加位置付订单
  642. * @param $data
  643. * @return mixed
  644. */
  645. private function createUnPayOrder($data)
  646. {
  647. $data['status'] = 'UNPAID';
  648. $data['transaction_id'] = '';
  649. $data['pay_end_at'] = '0000-00-00 00:00:00';
  650. return OrderService::save_order($data);
  651. }
  652. }