Membervrorder.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. use think\facade\Db;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 虚拟订单控制器
  15. */
  16. class Membervrorder extends MobileMember {
  17. public function initialize() {
  18. parent::initialize(); // TODO: Change the autogenerated stub
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberorder.lang.php');
  20. }
  21. /**
  22. * @api {POST} api/Membervrorder/order_list 订单列表
  23. * @apiVersion 1.0.0
  24. * @apiGroup Membervrorder
  25. *
  26. * @apiHeader {String} X-DS-KEY 用户授权token
  27. *
  28. * @apiParam {Int} page 当前页数
  29. * @apiParam {Int} state_type 订单状态 state_new待付款 state_pay待使用
  30. * @apiParam {String} order_key 订单编号
  31. * @apiParam {Int} per_page 每页数量
  32. *
  33. * @apiSuccess {String} code 返回码,10000为成功
  34. * @apiSuccess {String} message 返回消息
  35. * @apiSuccess {Object} result 返回数据
  36. * @apiSuccess {Object[]} result.order_list 订单列表 (返回字段参考vrorder表)
  37. * @apiSuccess {Object[]} result.order_list.code_list 未兑换的兑换码列表 (返回字段参考vrordercode表)
  38. * @apiSuccess {Int} result.order_list.if_cancel 是否可取消 true是false否
  39. * @apiSuccess {Int} result.order_list.if_pay 是否可支付 true是false否
  40. * @apiSuccess {Int} result.order_list.if_refund 是否可退款 true是false否
  41. * @apiSuccess {Int} result.order_list.if_evaluation 是否可评价 true是false否
  42. * @apiSuccess {String} result.order_list.goods_image_url 商品图片完整地址
  43. * @apiSuccess {Int} result.order_list.ownshop 是否自营店 true是false否
  44. * @apiSuccess {Int} result.order_list.if_refund_cancel 是否可全部退款 true是false否
  45. * @apiSuccess {Int} result.page_total 总页数
  46. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  47. */
  48. public function order_list() {
  49. $ownShopIds = model('store')->getOwnShopIds();
  50. $vrorder_model = model('vrorder');
  51. $condition = array();
  52. $condition[] = array('buyer_id', '=', $this->member_info['member_id']);
  53. if (preg_match('/^\d{10,20}$/', input('post.order_key'))) {
  54. $condition[] = array('order_sn', '=', input('post.order_key'));
  55. } elseif (input('post.order_key') != '') {
  56. $condition[] = array('goods_name', 'like', '%' . input('post.order_key') . '%');
  57. }
  58. if (input('post.state_type') != '') {
  59. $condition[] = array('order_state', '=', str_replace(array('state_new', 'state_pay'), array(ORDER_STATE_NEW, ORDER_STATE_PAY), input('post.state_type')));
  60. }
  61. $order_list = $vrorder_model->getVrorderList($condition, $this->pagesize, '*', 'order_id desc');
  62. //没有使用的兑换码列表
  63. $order_list = $vrorder_model->getCodeRefundList($order_list);
  64. foreach ($order_list as $key => $order) {
  65. //显示取消订单
  66. $order_list[$key]['if_cancel'] = $vrorder_model->getVrorderOperateState('buyer_cancel', $order);
  67. //显示支付
  68. $order_list[$key]['if_pay'] = $vrorder_model->getVrorderOperateState('payment', $order);
  69. //显示退款
  70. $order_list[$key]['if_refund'] = $vrorder_model->getVrorderOperateState('refund', $order);
  71. //显示评价
  72. $order_list[$key]['if_evaluation'] = $vrorder_model->getVrorderOperateState('evaluation', $order);
  73. $order_list[$key]['goods_image_url'] = goods_cthumb($order['goods_image'], 240, $order['store_id']);
  74. $order_list[$key]['ownshop'] = in_array($order['store_id'], $ownShopIds);
  75. }
  76. $result = array_merge(array('order_list' => $order_list), mobile_page($vrorder_model->page_info));
  77. ds_json_encode(10000, '', $result);
  78. }
  79. /**
  80. * @api {POST} api/Membervrorder/order_info 订单详情
  81. * @apiVersion 1.0.0
  82. * @apiGroup Membervrorder
  83. *
  84. * @apiHeader {String} X-DS-KEY 用户授权token
  85. *
  86. * @apiParam {Int} order_id 订单ID
  87. *
  88. * @apiSuccess {String} code 返回码,10000为成功
  89. * @apiSuccess {String} message 返回消息
  90. * @apiSuccess {Object} result 返回数据
  91. * @apiSuccess {Object[]} result.order_info 订单列表 (返回字段参考vrorder表)
  92. * @apiSuccess {Object[]} result.order_info.code_list 未兑换的兑换码列表 (返回字段参考vrordercode表)
  93. * @apiSuccess {Int} result.order_info.if_cancel 是否可取消 true是false否
  94. * @apiSuccess {Int} result.order_info.if_resend 是否可发送兑换码 true是false否
  95. * @apiSuccess {Int} result.order_info.if_refund 是否可退款 true是false否
  96. * @apiSuccess {Int} result.order_info.if_evaluation 是否可评价 true是false否
  97. * @apiSuccess {String} result.order_info.goods_image_url 商品图片完整地址
  98. * @apiSuccess {Int} result.order_info.ownshop 是否自营店 true是false否
  99. * @apiSuccess {Int} result.order_info.if_refund_cancel 是否可全部退款 true是false否
  100. */
  101. public function order_info() {
  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. $vrorder_model = model('vrorder');
  161. $condition = array();
  162. $condition[] = array('order_id','=',intval(input('post.order_id')));
  163. $condition[] = array('buyer_id','=',$this->member_info['member_id']);
  164. $order_info = $vrorder_model->getVrorderInfo($condition);
  165. $if_allow = $vrorder_model->getVrorderOperateState('buyer_cancel', $order_info);
  166. if (!$if_allow) {
  167. ds_json_encode(10001, lang('have_right_operate'));
  168. }
  169. $logic_vrorder = model('vrorder', 'logic');
  170. $result = $logic_vrorder->changeOrderStateCancel($order_info, 'buyer', lang('other_reason'));
  171. if (!$result['code']) {
  172. ds_json_encode(10001, $result['msg']);
  173. } else {
  174. ds_json_encode(10000, '');
  175. }
  176. }
  177. /**
  178. * 发送兑换码到手机
  179. */
  180. public function resend() {
  181. if (!preg_match('/^[\d]{11}$/', input('post.buyer_phone'))) {
  182. ds_json_encode(10001, lang('please_fill_phone_number_correctly'));
  183. }
  184. $order_id = intval(input('post.order_id'));
  185. if ($order_id <= 0) {
  186. ds_json_encode(10001, lang('param_error'));
  187. }
  188. $vrorder_model = model('vrorder');
  189. $condition = array();
  190. $condition[] = array('order_id','=',$order_id);
  191. $condition[] = array('buyer_id','=',$this->member_info['member_id']);
  192. $order_info = $vrorder_model->getVrorderInfo($condition);
  193. if (empty($order_info) && $order_info['order_state'] != ORDER_STATE_PAY) {
  194. ds_json_encode(10001, lang('error_order_information'));
  195. }
  196. if ($order_info['vr_send_times'] >= 5) {
  197. ds_json_encode(10001, lang('you_send_too_many_times'));
  198. }
  199. //发送兑换码到手机
  200. $param = array(
  201. 'order_id' => $order_id, 'buyer_id' => $this->member_info['member_id'],
  202. 'buyer_phone' => input('post.buyer_phone'), 'goods_name' => $order_info['goods_name']
  203. );
  204. $vrorder_model->sendVrCode($param);
  205. $vrorder_model->editVrorder(array('vr_send_times' => Db::raw('vr_send_times+1')), array('order_id' => $order_id));
  206. ds_json_encode(10000, '');
  207. }
  208. }