Memberpointorder.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 积分兑换控制器
  10. */
  11. class Memberpointorder extends MobileMember
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize();
  16. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberpoints.lang.php');
  17. //判断系统是否开启积分和积分兑换功能
  18. if (config('ds_config.points_isuse') != 1 || config('ds_config.pointprod_isuse') != 1) {
  19. ds_json_encode(10001, lang('points_unavailable'));
  20. die();
  21. }
  22. }
  23. public function index()
  24. {
  25. $this->orderlist();
  26. }
  27. /**
  28. * @api {POST} api/Memberpointorder/orderlist 兑换信息列表
  29. * @apiVersion 1.0.0
  30. * @apiGroup Memberpointorder
  31. *
  32. * @apiHeader {String} X-DS-KEY 用户授权token
  33. *
  34. * @apiParam {String} state_type 订单状态 state_pay待发货 state_finish已完成 state_send待收货 state_cancel已取消
  35. * @apiParam {String} order_key 订单号
  36. * @apiParam {Int} page 当前页数
  37. * @apiParam {Int} per_page 每页数量
  38. *
  39. * @apiSuccess {String} code 返回码,10000为成功
  40. * @apiSuccess {String} message 返回消息
  41. * @apiSuccess {Object} result 返回数据
  42. * @apiSuccess {Object[]} result.order_list 订单列表
  43. * @apiSuccess {Int} result.order_list.point_addtime 添加时间
  44. * @apiSuccess {Int} result.order_list.point_allpoint 兑换总积分
  45. * @apiSuccess {String} result.order_list.point_buyeremail 用户邮箱
  46. * @apiSuccess {Int} result.order_list.point_buyerid 用户ID
  47. * @apiSuccess {String} result.order_list.point_buyername 用户名称
  48. * @apiSuccess {Int} result.order_list.point_finnshedtime 完成时间
  49. * @apiSuccess {Boolean} result.order_list.point_orderallowcancel 允许取消 true是false否
  50. * @apiSuccess {Boolean} result.order_list.point_orderallowdelete 允许删除 true是false否
  51. * @apiSuccess {Boolean} result.order_list.point_orderalloweditship 允许修改发货信息 true是false否
  52. * @apiSuccess {Boolean} result.order_list.point_orderallowreceiving 允许收货 true是false否
  53. * @apiSuccess {Boolean} result.order_list.point_orderallowship 允许发货 true是false否
  54. * @apiSuccess {Int} result.order_list.point_orderid 订单ID
  55. * @apiSuccess {String} result.order_list.point_ordermessage 订单留言
  56. * @apiSuccess {String} result.order_list.point_ordersn 订单编号
  57. * @apiSuccess {Int} result.order_list.point_orderstate 订单状态
  58. * @apiSuccess {String} result.order_list.point_orderstatesign 订单状态代码
  59. * @apiSuccess {String} result.order_list.point_orderstatetext 订单状态描述
  60. * @apiSuccess {String} result.order_list.point_shipping_ecode 物流公司代码
  61. * @apiSuccess {String} result.order_list.point_shippingcode 物流单号
  62. * @apiSuccess {Int} result.order_list.point_shippingtime 发货时间
  63. * @apiSuccess {Object[]} result.order_list.prodlist 订单商品列表
  64. * @apiSuccess {String} result.order_list.prodlist.point_goodsimage_old 商品图片名称
  65. * @apiSuccess {String} result.order_list.prodlist.point_goodsimage_small 商品缩略图完整路径
  66. * @apiSuccess {Int} result.order_list.prodlist.pointog_goodsid 商品ID
  67. * @apiSuccess {String} result.order_list.prodlist.pointog_goodsimage 商品图片完整路径
  68. * @apiSuccess {String} result.order_list.prodlist.pointog_goodsname 商品名称
  69. * @apiSuccess {Int} result.order_list.prodlist.pointog_goodsnum 兑换数量
  70. * @apiSuccess {Int} result.order_list.prodlist.pointog_goodspoints 所需积分
  71. * @apiSuccess {Int} result.order_list.prodlist.pointog_orderid 订单ID
  72. * @apiSuccess {Int} result.order_list.prodlist.pointog_recid 订单商品ID
  73. * @apiSuccess {String} result.order_list.state_desc 状态描述
  74. * @apiSuccess {Int} result.page_total 总页数
  75. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  76. */
  77. public function orderlist()
  78. {
  79. //兑换信息列表
  80. $where = array();
  81. $where[] = array('point_buyerid', '=', $this->member_info['member_id']);
  82. $search_point_ordersn = input('param.order_key');
  83. if ($search_point_ordersn) {
  84. $where[] = array('point_ordersn', 'like', '%' . $search_point_ordersn . '%');
  85. }
  86. $state_type = input('param.state_type');
  87. switch ($state_type) {
  88. case 'state_pay':
  89. $where[] = array('point_orderstate', '=', '20');
  90. break;
  91. case 'state_finish':
  92. $where[] = array('point_orderstate', '=', '40');
  93. break;
  94. case 'state_send':
  95. $where[] = array('point_orderstate', '=', '30');
  96. break;
  97. case 'state_cancel':
  98. $where[] = array('point_orderstate', '=', '2');
  99. break;
  100. }
  101. $pointorder_model = model('pointorder');
  102. $order_list = $pointorder_model->getPointorderList($where, '*', 10, 0, 'point_orderid desc');
  103. $order_idarr = array();
  104. $order_listnew = array();
  105. if (is_array($order_list) && count($order_list) > 0) {
  106. foreach ($order_list as $k => $v) {
  107. $v['state_desc'] = '';
  108. switch ($v['point_orderstate']) {
  109. case '20';
  110. $v['state_desc'] = lang('member_pointorder_state_waitship');
  111. break;
  112. case '30';
  113. $v['state_desc'] = lang('member_pointorder_state_shipped');
  114. break;
  115. case '40';
  116. $v['state_desc'] = lang('member_pointorder_state_receive');
  117. break;
  118. case '50';
  119. $v['state_desc'] = lang('member_pointorder_state_finished');
  120. break;
  121. case '2';
  122. $v['state_desc'] = lang('member_pointorder_state_canceled');
  123. break;
  124. }
  125. $order_listnew[$v['point_orderid']] = $v;
  126. $order_idarr[] = $v['point_orderid'];
  127. }
  128. }
  129. $order_listnew1 = array();
  130. //查询兑换商品
  131. if (is_array($order_idarr) && count($order_idarr) > 0) {
  132. $prod_list = $pointorder_model->getPointordergoodsList(array(array('pointog_orderid', 'in', $order_idarr)));
  133. if (is_array($prod_list) && count($prod_list) > 0) {
  134. foreach ($prod_list as $v) {
  135. if (isset($order_listnew[$v['pointog_orderid']])) {
  136. $order_listnew[$v['pointog_orderid']]['prodlist'][] = $v;
  137. }
  138. }
  139. foreach ($order_listnew as $k => $v) {
  140. $order_listnew1[] = $v;
  141. }
  142. }
  143. }
  144. ds_json_encode(10000, '', array('order_list' => $order_listnew1));
  145. }
  146. /**
  147. * @api {POST} api/Memberpointorder/cancel_order 取消兑换
  148. * @apiVersion 1.0.0
  149. * @apiGroup Memberpointorder
  150. *
  151. * @apiHeader {String} X-DS-KEY 用户授权token
  152. *
  153. * @apiParam {Int} order_id 订单ID
  154. *
  155. * @apiSuccess {String} code 返回码,10000为成功
  156. * @apiSuccess {String} message 返回消息
  157. */
  158. public function cancel_order()
  159. {
  160. $pointorder_model = model('pointorder');
  161. //取消订单
  162. $data = $pointorder_model->cancelPointorder(input('post.order_id'), $this->member_info['member_id']);
  163. if ($data['state']) {
  164. ds_json_encode(10000, '', 1);
  165. } else {
  166. ds_json_encode(10001, lang('ds_common_op_fail'));
  167. die();
  168. }
  169. }
  170. /**
  171. * @api {POST} api/Memberpointorder/receiving_order 确认收货
  172. * @apiVersion 1.0.0
  173. * @apiGroup Memberpointorder
  174. *
  175. * @apiHeader {String} X-DS-KEY 用户授权token
  176. *
  177. * @apiParam {Int} order_id 订单ID
  178. *
  179. * @apiSuccess {String} code 返回码,10000为成功
  180. * @apiSuccess {String} message 返回消息
  181. */
  182. public function receiving_order()
  183. {
  184. $data = model('pointorder')->receivingPointorder(input('post.order_id'));
  185. if ($data['state']) {
  186. ds_json_encode(10000, '', 1);
  187. } else {
  188. ds_json_encode(10001, lang('ds_common_op_fail'));
  189. die();
  190. }
  191. }
  192. /**
  193. * @api {POST} api/Memberpointorder/order_info 兑换信息详细
  194. * @apiVersion 1.0.0
  195. * @apiGroup Memberpointorder
  196. *
  197. * @apiHeader {String} X-DS-KEY 用户授权token
  198. *
  199. * @apiParam {Int} order_id 订单ID
  200. *
  201. * @apiSuccess {String} code 返回码,10000为成功
  202. * @apiSuccess {String} message 返回消息
  203. * @apiSuccess {Object} result 返回数据
  204. * @apiSuccess {Object} result.express_info 物流公司信息
  205. * @apiSuccess {Object} result.order_info 订单信息
  206. * @apiSuccess {Int} result.order_info.point_addtime 添加时间
  207. * @apiSuccess {Int} result.order_info.point_allpoint 兑换总积分
  208. * @apiSuccess {String} result.order_info.point_buyeremail 用户邮箱
  209. * @apiSuccess {Int} result.order_info.point_buyerid 用户ID
  210. * @apiSuccess {String} result.order_info.point_buyername 用户名称
  211. * @apiSuccess {Int} result.order_info.point_finnshedtime 完成时间
  212. * @apiSuccess {Boolean} result.order_info.point_orderallowcancel 允许取消 true是false否
  213. * @apiSuccess {Boolean} result.order_info.point_orderallowdelete 允许删除 true是false否
  214. * @apiSuccess {Boolean} result.order_info.point_orderalloweditship 允许修改发货信息 true是false否
  215. * @apiSuccess {Boolean} result.order_info.point_orderallowreceiving 允许收货 true是false否
  216. * @apiSuccess {Boolean} result.order_info.point_orderallowship 允许发货 true是false否
  217. * @apiSuccess {Int} result.order_info.point_orderid 订单ID
  218. * @apiSuccess {String} result.order_info.point_ordermessage 订单留言
  219. * @apiSuccess {String} result.order_info.point_ordersn 订单编号
  220. * @apiSuccess {Int} result.order_info.point_orderstate 订单状态
  221. * @apiSuccess {String} result.order_info.point_orderstatesign 订单状态代码
  222. * @apiSuccess {String} result.order_info.point_orderstatetext 订单状态描述
  223. * @apiSuccess {String} result.order_info.point_shipping_ecode 物流公司代码
  224. * @apiSuccess {String} result.order_info.point_shippingcode 物流单号
  225. * @apiSuccess {Int} result.order_info.point_shippingtime 发货时间
  226. * @apiSuccess {String} result.order_info.state_desc 状态描述
  227. * @apiSuccess {Object} result.orderaddress_info 收货地址信息
  228. * @apiSuccess {String} result.orderaddress_info.pointoa_address 详细地址
  229. * @apiSuccess {String} result.orderaddress_info.pointoa_areaid 地区ID
  230. * @apiSuccess {String} result.orderaddress_info.pointoa_areainfo 地区名称
  231. * @apiSuccess {String} result.orderaddress_info.pointoa_id 地址ID
  232. * @apiSuccess {String} result.orderaddress_info.pointoa_mobphone 手机号
  233. * @apiSuccess {String} result.orderaddress_info.pointoa_orderid 订单ID
  234. * @apiSuccess {String} result.orderaddress_info.pointoa_telphone 座机号
  235. * @apiSuccess {String} result.orderaddress_info.pointoa_truename 真实姓名
  236. * @apiSuccess {String} result.orderaddress_info.pointoa_zipcode 邮编
  237. * @apiSuccess {Object} result.pointorderstate_arr 订单状态信息
  238. * @apiSuccess {Array} result.pointorderstate_arr.canceled 取消信息 值为状态ID以及状态描述
  239. * @apiSuccess {Array} result.pointorderstate_arr.finished 完成信息 值为状态ID以及状态描述
  240. * @apiSuccess {Array} result.pointorderstate_arr.waitreceiving 待收货信息 值为状态ID以及状态描述
  241. * @apiSuccess {Array} result.pointorderstate_arr.waitship 待发货信息 值为状态ID以及状态描述
  242. * @apiSuccess {Object[]} result.prod_list 订单状态信息
  243. * @apiSuccess {String} result.prodlist.point_goodsimage_old 商品图片名称
  244. * @apiSuccess {String} result.prodlist.point_goodsimage_small 商品缩略图完整路径
  245. * @apiSuccess {Int} result.prodlist.pointog_goodsid 商品ID
  246. * @apiSuccess {String} result.prodlist.pointog_goodsimage 商品图片完整路径
  247. * @apiSuccess {String} result.prodlist.pointog_goodsname 商品名称
  248. * @apiSuccess {Int} result.prodlist.pointog_goodsnum 兑换数量
  249. * @apiSuccess {Int} result.prodlist.pointog_goodspoints 所需积分
  250. * @apiSuccess {Int} result.prodlist.pointog_orderid 订单ID
  251. * @apiSuccess {Int} result.prodlist.pointog_recid 订单商品ID
  252. */
  253. public function order_info()
  254. {
  255. $order_id = intval(input('param.order_id'));
  256. if ($order_id <= 0) {
  257. ds_json_encode(10001, lang('param_error'));
  258. die();
  259. }
  260. $pointorder_model = model('pointorder');
  261. //查询兑换订单信息
  262. $condition = array();
  263. $condition[] = array('point_orderid', '=', $order_id);
  264. $condition[] = array('point_buyerid', '=', $this->member_info['member_id']);
  265. $order_info = $pointorder_model->getPointorderInfo($condition);
  266. if (!$order_info) {
  267. ds_json_encode(10001, lang('cart_order_pay_not_exists'));
  268. die();
  269. }
  270. if ($order_info['point_addtime']) {
  271. $order_info['point_addtime'] = date('Y-m-d H:i:s', $order_info['point_addtime']);
  272. } else {
  273. $order_info['point_addtime'] = '';
  274. }
  275. if ($order_info['point_shippingtime']) {
  276. $order_info['point_shippingtime'] = date('Y-m-d H:i:s', $order_info['point_shippingtime']);
  277. } else {
  278. $order_info['point_shippingtime'] = '';
  279. }
  280. if ($order_info['point_finnshedtime']) {
  281. $order_info['point_finnshedtime'] = date('Y-m-d H:i:s', $order_info['point_finnshedtime']);
  282. } else {
  283. $order_info['point_finnshedtime'] = '';
  284. }
  285. //获取订单状态
  286. $pointorderstate_arr = $pointorder_model->getPointorderStateBySign();
  287. //查询兑换订单收货人地址
  288. $orderaddress_info = $pointorder_model->getPointorderAddressInfo(array('pointoa_orderid' => $order_id));
  289. //兑换商品信息
  290. $prod_list = $pointorder_model->getPointordergoodsList(array('pointog_orderid' => $order_id));
  291. //物流公司信息
  292. $express_info = "";
  293. if ($order_info['point_shipping_ecode'] != '') {
  294. $data = model('express')->getExpressInfoByECode($order_info['point_shipping_ecode']);
  295. if ($data['state']) {
  296. $express_info = $data['data']['express_info'];
  297. }
  298. }
  299. ds_json_encode(10000, '', array('order_info' => $order_info, 'express_info' => $express_info, 'prod_list' => $prod_list, 'orderaddress_info' => $orderaddress_info, 'pointorderstate_arr' => $pointorderstate_arr));
  300. }
  301. /**
  302. * @api {POST} api/Memberorder/search_deliver 物流跟踪
  303. * @apiVersion 1.0.0
  304. * @apiGroup Memberorder
  305. *
  306. * @apiHeader {String} X-DS-KEY 用户授权token
  307. *
  308. * @apiParam {String} order_id 订单id
  309. *
  310. * @apiSuccess {String} code 返回码,10000为成功
  311. * @apiSuccess {String} message 返回消息
  312. * @apiSuccess {Object} result 返回数据
  313. * @apiSuccess {String} result.express_name 物流公司名称
  314. * @apiSuccess {String} result.shipping_code 物流单号
  315. * @apiSuccess {Object[]} result.deliver_info 物流数据
  316. * @apiSuccess {String} result.deliver_info.context 内容
  317. * @apiSuccess {String} result.deliver_info.time 时间
  318. */
  319. public function search_deliver()
  320. {
  321. $order_id = intval(input('post.order_id'));
  322. if ($order_id <= 0) {
  323. ds_json_encode(10001, lang('member_order_none_exist'));
  324. }
  325. $pointorder_model = model('pointorder');
  326. $condition[] = array('point_orderid', '=', $order_id);
  327. $condition[] = array('point_buyerid', '=', $this->member_info['member_id']);
  328. $order_info = $pointorder_model->getPointorderInfo($condition);
  329. if (!$order_info) {
  330. ds_json_encode(10001, lang('cart_order_pay_not_exists'));
  331. die();
  332. }
  333. //查询兑换订单收货人地址
  334. $orderaddress_info = $pointorder_model->getPointorderAddressInfo(array('pointoa_orderid' => $order_id));
  335. //快递公司信息
  336. $express = rkcache('express', true);
  337. $express_code = $order_info['point_shipping_ecode'];
  338. $expresslist = array_filter($express, function ($t) use ($express_code) {
  339. return $t['express_code'] == $express_code;
  340. });
  341. foreach ($expresslist as $key => $val) {
  342. $expressinfo = $val;
  343. }
  344. if (!empty($expressinfo)) {
  345. $express_code = $order_info['point_shipping_ecode'];
  346. $express_name = $expressinfo['express_name'];
  347. $deliver_info = Memberorder::_get_express($express_code, $order_info['point_shippingcode'], $orderaddress_info['pointoa_mobphone']);
  348. } else {
  349. $express_name = '';
  350. $deliver_info = array();
  351. }
  352. ds_json_encode(10000, '', array('express_name' => $express_name, 'shipping_code' => $order_info['point_shippingcode'], 'deliver_info' => $deliver_info));
  353. }
  354. }