OrdersController.php 24 KB

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