OrdersController.php 25 KB

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