OrdersController.php 24 KB

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