Memberpointorder.php 18 KB

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