OrdersController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <?php
  2. namespace App\Http\Controllers\WapAlipay\Order;
  3. use App\Http\Controllers\WapAlipay\BaseController;
  4. use Illuminate\Http\Request;
  5. use App\Modules\Subscribe\Services\BookOrderService;
  6. use App\Modules\Subscribe\Services\ChapterOrderService;
  7. use App\Modules\Subscribe\Services\OrderService;
  8. use App\Http\Controllers\WapAlipay\Order\Transformers\BookOrderTransformer;
  9. use App\Http\Controllers\WapAlipay\Order\Transformers\ChapterOrderTransformer;
  10. use App\Http\Controllers\WapAlipay\Order\Transformers\ChargeListTransformer;
  11. use App\Modules\Product\Services\ProductService;
  12. class OrdersController extends BaseController
  13. {
  14. /**
  15. * @apiDefine Order 订单
  16. */
  17. /**
  18. * @apiVersion 1.0.0
  19. * @apiDescription 充值列表
  20. * @api {get} order/chargeList 充值列表
  21. * @apiGroup Order
  22. * @apiName chargeList
  23. * @apiSuccess {int} code 状态码
  24. * @apiSuccess {String} msg 信息
  25. * @apiSuccess {object} data 结果集
  26. * @apiSuccessExample {json} Success-Response:
  27. * HTTP/1.1 200 OK
  28. * {
  29. * code: 0,
  30. * msg: "",
  31. * data: [
  32. * {
  33. * product_id: 1,
  34. * price: "30.00元",
  35. * vip: 0,
  36. * intro: [
  37. * {
  38. * label: 3000,
  39. * important: false
  40. * },
  41. * {
  42. * label: "书币",
  43. * important: true
  44. * }
  45. * ]
  46. * },
  47. * {
  48. * product_id: 2,
  49. * price: "50.00元",
  50. * vip: 1,
  51. * intro: [
  52. * {
  53. * label: 5000,
  54. * important: false
  55. * },
  56. * {
  57. * label: "1000+",
  58. * important: true
  59. * },
  60. * {
  61. * label: "书币",
  62. * important: false
  63. * }
  64. * ]
  65. * },
  66. * {
  67. * product_id: 5,
  68. * price: "365.00元",
  69. * vip: 0,
  70. * intro: [
  71. * {
  72. * label: "年费VIP会员",
  73. * important: true
  74. * }
  75. * ]
  76. * }
  77. * ]
  78. * }
  79. */
  80. public function chargeList(Request $request)
  81. {
  82. if (!$this->checkUid()) {
  83. return response()->error('WAP_NOT_LOGIN');
  84. }
  85. $res = ProductService::getChargeProduct();
  86. if (!$res->isEmpty()) {
  87. $data = [];
  88. foreach ($res as $v) {
  89. $intro = [];
  90. if ($v->given > 0 && $v->type == 'TICKET_RECHARGE') {
  91. $intro = [
  92. [
  93. 'label' => ($v->price * 100) . "+",
  94. 'important' => false,
  95. ],
  96. [
  97. 'label' => $v->given,
  98. 'important' => true,
  99. ],
  100. [
  101. 'label' => '书币',
  102. 'important' => false,
  103. ]
  104. ];
  105. $intro2 = [
  106. ['label'=>'多送','important'=>false],
  107. ['label'=>(int)($v->given/100),'important'=>true],
  108. ['label'=>'元','important'=>false],
  109. ];
  110. $v->vip = 0;
  111. }
  112. if ($v->given == 0 && $v->type == 'TICKET_RECHARGE') {
  113. $intro = [
  114. [
  115. 'label' => $v->price * 100,
  116. 'important' => false,
  117. ],
  118. [
  119. 'label' => '书币',
  120. 'important' => false,
  121. ]
  122. ];
  123. $v->vip = 0;
  124. $intro2 = [];
  125. }
  126. if ($v->given == 0 && $v->type == 'YEAR_ORDER') {
  127. $intro = [
  128. [
  129. 'label' => '年费VIP会员',
  130. 'important' => true,
  131. ]
  132. ];
  133. $v->vip = 1;
  134. $intro2 = [
  135. ['label'=>'每天1元,全年免费看','important'=>false],
  136. ];
  137. }
  138. $data[] = [
  139. 'product_id' => $v->id,
  140. 'price' => (int)$v->price . '元',
  141. 'vip' => $v->vip,
  142. 'intro' => $intro,
  143. 'intro2'=>$intro2,
  144. 'is_default' => $v->is_default,
  145. ];
  146. }
  147. return response()->success($data);
  148. } else {
  149. return response()->error('WAP_SYS_ERROR');
  150. }
  151. }
  152. /**
  153. * @apiVersion 1.0.0
  154. * @apiDescription 单本消费记录
  155. * @api {get} order/bookOrderList 单本消费记录
  156. * @apiGroup Order
  157. * @apiName bookOrderList
  158. * @apiSuccess {int} code 状态码
  159. * @apiSuccess {String} msg 信息
  160. * @apiSuccess {object} data 结果集
  161. * @apiSuccess {Int} uid uid
  162. * @apiSuccess {Int} bid bid
  163. * @apiSuccess {Int} book_name 书名
  164. * @apiSuccess {Int} fee 钱
  165. * @apiSuccess {String} created_at 时间
  166. * @apiSuccessExample {json} Success-Response:
  167. * HTTP/1.1 200 OK
  168. * {
  169. * code: 0,
  170. * msg: "",
  171. * data: list:[
  172. * {
  173. * uid: 4,
  174. * bid: 1,
  175. * book_name: "dfsedfertrwet",
  176. * fee: 100,
  177. * created_at: "2017-12-02 16:24:54"
  178. * }
  179. * ]
  180. * meta: {
  181. * total: 1,
  182. * per_page: 15,
  183. * current_page: 1,
  184. * last_page: 1,
  185. * next_page_url: "",
  186. * prev_page_url: ""
  187. * }
  188. * }
  189. */
  190. public function bookOrderList(Request $request)
  191. {
  192. if (!$this->checkUid()) {
  193. return response()->error('WAP_NOT_LOGIN');
  194. }
  195. $page_size = $request->input('page_size', 15);
  196. $book_order = BookOrderService::getRecord($this->uid, $page_size);
  197. //$book_order = BookOrder::where('uid', $this->uid)->select('bid', 'uid', 'book_name', 'created_at', 'fee')->paginate($page_size);
  198. return response()->pagination(new BookOrderTransformer(), $book_order);
  199. }
  200. /**
  201. * @apiVersion 1.0.0
  202. * @apiDescription 章节消费记录
  203. * @api {get} order/chapterOrderList 章节消费记录
  204. * @apiGroup Order
  205. * @apiName chapterOrderList
  206. * @apiSuccess {int} code 状态码
  207. * @apiSuccess {String} msg 信息
  208. * @apiSuccess {object} data 结果集
  209. * @apiSuccess {Int} uid uid
  210. * @apiSuccess {Int} bid bid
  211. * @apiSuccess {Int} cid cid
  212. * @apiSuccess {Int} chapter_name 章节名
  213. * @apiSuccess {Int} book_name 书名
  214. * @apiSuccess {Int} fee 钱
  215. * @apiSuccess {String} created_at 时间
  216. * @apiSuccessExample {json} Success-Response:
  217. * HTTP/1.1 200 OK
  218. * {
  219. * code: 0,
  220. * msg: "",
  221. * data: list:[
  222. * {
  223. * uid: 4,
  224. * bid: 1,
  225. * cid: 1,
  226. * chapter_name: "sdfsd",
  227. * book_name: "dfsedfertrwet",
  228. * fee: 100,
  229. * created_at: "2017-12-02 16:24:54"
  230. * }
  231. * ]
  232. * meta: {
  233. * total: 1,
  234. * per_page: 15,
  235. * current_page: 1,
  236. * last_page: 1,
  237. * next_page_url: "",
  238. * prev_page_url: ""
  239. * }
  240. * }
  241. */
  242. public function chapterOrderList(Request $request)
  243. {
  244. if (!$this->checkUid()) {
  245. return response()->error('WAP_NOT_LOGIN');
  246. }
  247. $chapter_model = new ChapterOrderService();
  248. $page_size = $request->input('page_size', 15);
  249. $chapter_order = $chapter_model->getByUid($this->uid, $page_size);
  250. return response()->pagination(new ChapterOrderTransformer(), $chapter_order);
  251. }
  252. /**
  253. * @apiVersion 1.0.0
  254. * @apiDescription 充值记录
  255. * @api {get} order/chargeRecordLists 充值记录
  256. * @apiGroup Order
  257. * @apiName chargeRecordLists
  258. * @apiSuccess {int} code 状态码
  259. * @apiSuccess {String} msg 信息
  260. * @apiSuccess {object} data 结果集
  261. * @apiSuccess {String} data.price 价格
  262. * @apiSuccess {String} data.status 状态
  263. * @apiSuccess {String} data.trade_no 订单号
  264. * @apiSuccess {String} data.created_at 时间
  265. * @apiSuccessExample {json} Success-Response:
  266. * HTTP/1.1 200 OK
  267. * {
  268. * code: 0,
  269. * msg: "",
  270. * data: {
  271. * list: [
  272. * {
  273. * id: 134,
  274. * price: "1.00",
  275. * status: "PAID",
  276. * trade_no: "201712021915481585670623626232",
  277. * created_at: "2017-12-02 19:15:56"
  278. * }
  279. * ],
  280. * meta: {
  281. * total: 1,
  282. * per_page: 15,
  283. * current_page: 1,
  284. * last_page: 1,
  285. * next_page_url: "",
  286. * prev_page_url: ""
  287. * }
  288. * }
  289. * }
  290. */
  291. public function chargeRecordLists(Request $request)
  292. {
  293. $page_size = $request->input('page_size', 15);
  294. $res = OrderService::getOrderList($this->uid, $page_size);
  295. return response()->pagination(new ChargeListTransformer(), $res);
  296. }
  297. //订单是否成功
  298. public function isSuccess(Request $request){
  299. $order = $request->input('order');
  300. $order_info = OrderService::getByTradeNo($order);
  301. if($order_info && $order_info->status == 'PAID'){
  302. return response()->success();
  303. }
  304. return response()->error('WAP_SYS_ERROR');
  305. }
  306. }