Memberpointorder.php 18 KB

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