Membervrorder.php 11 KB

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