Membervrorder.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. use think\facade\Db;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 虚拟订单控制器
  11. */
  12. class Membervrorder extends MobileMember
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize(); // TODO: Change the autogenerated stub
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberorder.lang.php');
  18. }
  19. /**
  20. * @api {POST} api/Membervrorder/order_list 订单列表
  21. * @apiVersion 1.0.0
  22. * @apiGroup Membervrorder
  23. *
  24. * @apiHeader {String} X-DS-KEY 用户授权token
  25. *
  26. * @apiParam {Int} page 当前页数
  27. * @apiParam {Int} state_type 订单状态 state_new待付款 state_pay待使用
  28. * @apiParam {String} order_key 订单编号
  29. * @apiParam {Int} per_page 每页数量
  30. *
  31. * @apiSuccess {String} code 返回码,10000为成功
  32. * @apiSuccess {String} message 返回消息
  33. * @apiSuccess {Object} result 返回数据
  34. * @apiSuccess {Object[]} result.order_list 订单列表 (返回字段参考vrorder表)
  35. * @apiSuccess {Object[]} result.order_list.code_list 未兑换的兑换码列表 (返回字段参考vrordercode表)
  36. * @apiSuccess {Int} result.order_list.if_cancel 是否可取消 true是false否
  37. * @apiSuccess {Int} result.order_list.if_pay 是否可支付 true是false否
  38. * @apiSuccess {Int} result.order_list.if_refund 是否可退款 true是false否
  39. * @apiSuccess {Int} result.order_list.if_evaluation 是否可评价 true是false否
  40. * @apiSuccess {String} result.order_list.goods_image_url 商品图片完整地址
  41. * @apiSuccess {Int} result.order_list.ownshop 是否自营店 true是false否
  42. * @apiSuccess {Int} result.order_list.if_refund_cancel 是否可全部退款 true是false否
  43. * @apiSuccess {Int} result.page_total 总页数
  44. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  45. */
  46. public function order_list()
  47. {
  48. $ownShopIds = model('store')->getOwnShopIds();
  49. $vrorder_model = model('vrorder');
  50. $condition = array();
  51. $condition[] = array('buyer_id', '=', $this->member_info['member_id']);
  52. if (preg_match('/^\d{10,20}$/', input('post.order_key'))) {
  53. $condition[] = array('order_sn', '=', input('post.order_key'));
  54. } elseif (input('post.order_key') != '') {
  55. $condition[] = array('goods_name', 'like', '%' . input('post.order_key') . '%');
  56. }
  57. if (input('post.state_type') != '') {
  58. $condition[] = array('order_state', '=', str_replace(array('state_new', 'state_pay'), array(ORDER_STATE_NEW, ORDER_STATE_PAY), input('post.state_type')));
  59. }
  60. $order_list = $vrorder_model->getVrorderList($condition, $this->pagesize, '*', 'order_id desc');
  61. //没有使用的兑换码列表
  62. $order_list = $vrorder_model->getCodeRefundList($order_list);
  63. foreach ($order_list as $key => $order) {
  64. //显示取消订单
  65. $order_list[$key]['if_cancel'] = $vrorder_model->getVrorderOperateState('buyer_cancel', $order);
  66. //显示支付
  67. $order_list[$key]['if_pay'] = $vrorder_model->getVrorderOperateState('payment', $order);
  68. //显示退款
  69. $order_list[$key]['if_refund'] = $vrorder_model->getVrorderOperateState('refund', $order);
  70. //显示评价
  71. $order_list[$key]['if_evaluation'] = $vrorder_model->getVrorderOperateState('evaluation', $order);
  72. $order_list[$key]['goods_image_url'] = goods_cthumb($order['goods_image'], 240, $order['store_id']);
  73. $order_list[$key]['ownshop'] = in_array($order['store_id'], $ownShopIds);
  74. }
  75. $result = array_merge(array('order_list' => $order_list), mobile_page($vrorder_model->page_info));
  76. ds_json_encode(10000, '', $result);
  77. }
  78. /**
  79. * @api {POST} api/Membervrorder/order_info 订单详情
  80. * @apiVersion 1.0.0
  81. * @apiGroup Membervrorder
  82. *
  83. * @apiHeader {String} X-DS-KEY 用户授权token
  84. *
  85. * @apiParam {Int} order_id 订单ID
  86. *
  87. * @apiSuccess {String} code 返回码,10000为成功
  88. * @apiSuccess {String} message 返回消息
  89. * @apiSuccess {Object} result 返回数据
  90. * @apiSuccess {Object[]} result.order_info 订单列表 (返回字段参考vrorder表)
  91. * @apiSuccess {Object[]} result.order_info.code_list 未兑换的兑换码列表 (返回字段参考vrordercode表)
  92. * @apiSuccess {Int} result.order_info.if_cancel 是否可取消 true是false否
  93. * @apiSuccess {Int} result.order_info.if_resend 是否可发送兑换码 true是false否
  94. * @apiSuccess {Int} result.order_info.if_refund 是否可退款 true是false否
  95. * @apiSuccess {Int} result.order_info.if_evaluation 是否可评价 true是false否
  96. * @apiSuccess {String} result.order_info.goods_image_url 商品图片完整地址
  97. * @apiSuccess {Int} result.order_info.ownshop 是否自营店 true是false否
  98. * @apiSuccess {Int} result.order_info.if_refund_cancel 是否可全部退款 true是false否
  99. */
  100. public function order_info()
  101. {
  102. $order_id = intval(input('param.order_id'));
  103. if ($order_id <= 0) {
  104. ds_json_encode(10001, lang('param_error'));
  105. }
  106. $vrorder_model = model('vrorder');
  107. $condition = array();
  108. $condition[] = array('order_id', '=', $order_id);
  109. $condition[] = array('buyer_id', '=', $this->member_info['member_id']);
  110. $order_info = $vrorder_model->getVrorderInfo($condition);
  111. if (empty($order_info) || $order_info['delete_state'] == ORDER_DEL_STATE_DROP) {
  112. ds_json_encode(10001, lang('member_order_none_exist'));
  113. }
  114. $order_list = array();
  115. $order_list[$order_id] = $order_info;
  116. $order_list = $vrorder_model->getCodeRefundList($order_list); //没有使用的兑换码列表
  117. $order_info = $order_list[$order_id];
  118. //显示取消订单
  119. $order_info['if_cancel'] = $vrorder_model->getVrorderOperateState('buyer_cancel', $order_info);
  120. //显示评价
  121. $order_info['if_evaluation'] = $vrorder_model->getVrorderOperateState('evaluation', $order_info);
  122. //显示退款
  123. $order_info['if_refund'] = $vrorder_model->getVrorderOperateState('refund', $order_info);
  124. $order_info['goods_image_url'] = goods_cthumb($order_info['goods_image'], 240, $order_info['store_id']);
  125. $ownShopIds = model('store')->getOwnShopIds();
  126. $order_info['ownshop'] = in_array($order_info['store_id'], $ownShopIds);
  127. $order_info['vr_indate'] = $order_info['vr_indate'] ? date('Y-m-d', $order_info['vr_indate']) : '';
  128. $order_info['add_time'] = date('Y-m-d H:i:s', $order_info['add_time']);
  129. $order_info['payment_time'] = $order_info['payment_time'] ? date('Y-m-d H:i:s', $order_info['payment_time']) : '';
  130. $order_info['finnshed_time'] = $order_info['finnshed_time'] ? date('Y-m-d H:i:s', $order_info['finnshed_time']) : '';
  131. $order_info['if_resend'] = $order_info['order_state'] == ORDER_STATE_PAY ? true : false;
  132. //取兑换码列表
  133. $vr_code_list = $vrorder_model->getShowVrordercodeList(array('order_id' => $order_info['order_id']));
  134. $order_info['code_list'] = $vr_code_list ? $vr_code_list : array();
  135. if ($order_info['order_state'] == ORDER_STATE_SUCCESS) {
  136. if ($order_info['virtual_type'] == 3) {
  137. $order_info['vc_file_url'] = goods_resource($order_info['virtual_content']);
  138. } else if ($order_info['virtual_type'] == 1) {
  139. $order_info['virtual_content'] = explode('\r\n', $order_info['virtual_content']);
  140. }
  141. } else {
  142. $order_info['virtual_content'] = '';
  143. }
  144. ds_json_encode(10000, '', array('order_info' => $order_info));
  145. }
  146. /**
  147. * @api {POST} api/Membervrorder/order_cancel 取消订单
  148. * @apiVersion 1.0.0
  149. * @apiGroup Membervrorder
  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. * @apiSuccess {Object} result 返回数据
  158. */
  159. public function order_cancel()
  160. {
  161. $vrorder_model = model('vrorder');
  162. $condition = array();
  163. $condition[] = array('order_id', '=', intval(input('post.order_id')));
  164. $condition[] = array('buyer_id', '=', $this->member_info['member_id']);
  165. $order_info = $vrorder_model->getVrorderInfo($condition);
  166. $if_allow = $vrorder_model->getVrorderOperateState('buyer_cancel', $order_info);
  167. if (!$if_allow) {
  168. ds_json_encode(10001, lang('have_right_operate'));
  169. }
  170. $logic_vrorder = model('vrorder', 'logic');
  171. $result = $logic_vrorder->changeOrderStateCancel($order_info, 'buyer', lang('other_reason'));
  172. if (!$result['code']) {
  173. ds_json_encode(10001, $result['msg']);
  174. } else {
  175. ds_json_encode(10000, '');
  176. }
  177. }
  178. /**
  179. * 发送兑换码到手机
  180. */
  181. public function resend()
  182. {
  183. if (!preg_match('/^[\d]{11}$/', input('post.buyer_phone'))) {
  184. ds_json_encode(10001, lang('please_fill_phone_number_correctly'));
  185. }
  186. $order_id = intval(input('post.order_id'));
  187. if ($order_id <= 0) {
  188. ds_json_encode(10001, lang('param_error'));
  189. }
  190. $vrorder_model = model('vrorder');
  191. $condition = array();
  192. $condition[] = array('order_id', '=', $order_id);
  193. $condition[] = array('buyer_id', '=', $this->member_info['member_id']);
  194. $order_info = $vrorder_model->getVrorderInfo($condition);
  195. if (empty($order_info) && $order_info['order_state'] != ORDER_STATE_PAY) {
  196. ds_json_encode(10001, lang('error_order_information'));
  197. }
  198. if ($order_info['vr_send_times'] >= 5) {
  199. ds_json_encode(10001, lang('you_send_too_many_times'));
  200. }
  201. //发送兑换码到手机
  202. $param = array(
  203. 'order_id' => $order_id, 'buyer_id' => $this->member_info['member_id'],
  204. 'buyer_phone' => input('post.buyer_phone'), 'goods_name' => $order_info['goods_name']
  205. );
  206. $vrorder_model->sendVrCode($param);
  207. $vrorder_model->editVrorder(array('vr_send_times' => Db::raw('vr_send_times+1')), array('order_id' => $order_id));
  208. ds_json_encode(10000, '');
  209. }
  210. }