Sellervrorder.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 Sellervrorder extends MobileSeller {
  17. public function initialize() {
  18. parent::initialize(); // TODO: Change the autogenerated stub
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellervrorder.lang.php');
  20. }
  21. /**
  22. * @api {POST} api/Sellervrorder/order_list 虚拟订单列表
  23. * @apiVersion 1.0.0
  24. * @apiGroup Sellervrorder
  25. *
  26. * @apiHeader {String} X-DS-KEY 卖家授权token
  27. *
  28. * @apiParam {String} order_sn 订单号
  29. * @apiParam {Int} skip_off 非取消状态 1是
  30. * @apiParam {String} state_type 订单状态 state_new待付款 state_pay待使用 state_success已完成 state_cancel已取消
  31. * @apiParam {String} query_start_date 开始日期 YYYY-MM-DD
  32. * @apiParam {String} query_end_date 结束日期 YYYY-MM-DD
  33. * @apiParam {String} page 页码
  34. * @apiParam {String} pagesize 每页显示数量
  35. *
  36. * @apiSuccess {String} code 返回码,10000为成功
  37. * @apiSuccess {String} message 返回消息
  38. * @apiSuccess {Object} result 返回数据
  39. * @apiSuccess {Object[]} result.order_list 订单列表 (返回字段参考vrorder)
  40. * @apiSuccess {Boolean} result.order_list.if_cancel 是否可取消 true是false否
  41. * @apiSuccess {String} result.order_list.goods_image_url 商品图片完整路径
  42. * @apiSuccess {Int} result.page_total 总页数
  43. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  44. */
  45. public function order_list() {
  46. $vrorder_model = model('vrorder');
  47. $condition = array();
  48. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  49. $order_key = input('post.order_sn');
  50. if (preg_match('/^\d{10,20}$/', $order_key)) {
  51. $condition[] = array('order_sn', '=', $order_key);
  52. } elseif ($order_key != '') {
  53. $condition[] = array('goods_name', 'like', '%' . $order_key . '%');
  54. }
  55. $state_type = input('post.state_type');
  56. if ($state_type != '') {
  57. $condition[] = array('order_state', '=', str_replace(
  58. $allow_state_array = array('state_new', 'state_pay', 'state_success', 'state_cancel'), array(ORDER_STATE_NEW, ORDER_STATE_PAY, ORDER_STATE_SUCCESS, ORDER_STATE_CANCEL), $state_type));
  59. }
  60. $query_start_date = input('post.query_start_date');
  61. $query_end_date = input('post.query_end_date');
  62. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
  63. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
  64. $start_unixtime = $if_start_date ? strtotime($query_start_date) : null;
  65. $end_unixtime = $if_end_date ? strtotime($query_end_date) : null;
  66. if ($start_unixtime || $end_unixtime) {
  67. $condition[] = array('add_time', 'time', array($start_unixtime, $end_unixtime));
  68. }
  69. if (input('post.skip_off') == 1) {
  70. $condition[] = array('order_state', '<>', ORDER_STATE_CANCEL);
  71. }
  72. $order_list = $vrorder_model->getVrorderList($condition, $this->pagesize, '*', 'order_id desc');
  73. $mobile_page = $vrorder_model->page_info;
  74. foreach ($order_list as $key => $order) {
  75. //显示取消订单
  76. $order_list[$key]['if_cancel'] = $vrorder_model->getVrorderOperateState('store_cancel', $order);
  77. $order_list[$key]['goods_image_url'] = goods_cthumb($order['goods_image'], 240, $order['store_id']);
  78. }
  79. $result = array_merge(array('order_list' => $order_list), mobile_page($mobile_page));
  80. ds_json_encode(10000, '', $result);
  81. }
  82. /**
  83. * @api {POST} api/Sellervrorder/order_cancel 取消虚拟订单
  84. * @apiVersion 1.0.0
  85. * @apiGroup Sellervrorder
  86. *
  87. * @apiHeader {String} X-DS-KEY 卖家授权token
  88. *
  89. * @apiParam {String} order_id 订单id
  90. * @apiParam {String} reason 理由
  91. *
  92. * @apiSuccess {String} code 返回码,10000为成功
  93. * @apiSuccess {String} message 返回消息
  94. * @apiSuccess {Object} result 返回数据
  95. */
  96. public function order_cancel() {
  97. $order_id = intval(input('post.order_id'));
  98. $reason = input('post.reason');
  99. $vrorder_model = model('vrorder');
  100. $logic_vrorder = model('vrorder', 'logic');
  101. $condition = array();
  102. $condition[] = array('order_id','=',$order_id);
  103. $condition[] = array('store_id','=',$this->store_info['store_id']);
  104. $order_info = $vrorder_model->getVrorderInfo($condition);
  105. $if_allow = $vrorder_model->getVrorderOperateState('store_cancel', $order_info);
  106. if (!$if_allow) {
  107. return callback(false, lang('have_right_operate'));
  108. }
  109. $result = $logic_vrorder->changeOrderStateCancel($order_info, 'seller', $reason, true);
  110. if (!$result['code']) {
  111. ds_json_encode(10001, $result['msg']);
  112. }
  113. ds_json_encode(10000, '', 1);
  114. }
  115. /**
  116. * @api {POST} api/Sellervrorder/exchange 兑换码消费
  117. * @apiVersion 1.0.0
  118. * @apiGroup Sellervrorder
  119. *
  120. * @apiHeader {String} X-DS-KEY 卖家授权token
  121. *
  122. * @apiParam {String} vr_code 兑换码
  123. *
  124. * @apiSuccess {String} code 返回码,10000为成功
  125. * @apiSuccess {String} message 返回消息
  126. * @apiSuccess {Object} result 订单信息 (返回字段参考vrorder)
  127. */
  128. public function exchange() {
  129. $vr_code = input('param.vr_code');
  130. if ($vr_code) {
  131. if (!preg_match('/^[a-zA-Z0-9]{15,18}$/', $vr_code)) {
  132. ds_json_encode(10001, lang('exchange_code_format_error'));
  133. }
  134. $vrorder_model = model('vrorder');
  135. $vr_code_info = $vrorder_model->getVrordercodeInfo(array('vr_code' => $vr_code));
  136. if (empty($vr_code_info) || $vr_code_info['store_id'] != $this->store_info['store_id']) {
  137. ds_json_encode(10001, lang('exchange_code_not_exist'));
  138. }
  139. if ($vr_code_info['vr_state'] == '1') {
  140. ds_json_encode(10001, lang('exchange_code_been_used'));
  141. }
  142. if ($vr_code_info['vr_indate'] < TIMESTAMP) {
  143. ds_json_encode(10001, lang('exchange_code_expired') . date('Y-m-d H:i:s', $vr_code_info['vr_indate']));
  144. }
  145. if ($vr_code_info['refund_lock'] > 0) {//退款锁定状态:0为正常,1为锁定(待审核),2为同意
  146. ds_json_encode(10001, lang('exchange_code_been_applied_refund'));
  147. }
  148. //更新兑换码状态
  149. $update = array();
  150. $update['vr_state'] = 1;
  151. $update['vr_usetime'] = TIMESTAMP;
  152. $update = $vrorder_model->editVrorderCode($update, array('vr_code' => $vr_code));
  153. //如果全部兑换完成,更新订单状态
  154. model('vrorder', 'logic')->changeOrderStateSuccess($vr_code_info['order_id']);
  155. if ($update) {
  156. //取得返回信息
  157. $order_info = $vrorder_model->getVrorderInfo(array('order_id' => $vr_code_info['order_id']));
  158. if ($order_info['use_state'] == '0') {
  159. $vrorder_model->editVrorder(array('use_state' => 1), array('order_id' => $vr_code_info['order_id']));
  160. }
  161. $order_info['img_240'] = goods_thumb($order_info, 240);
  162. ds_json_encode(10000, lang('exchange_successful'), $order_info);
  163. }
  164. } else {
  165. ds_json_encode(10001, lang('param_error'));
  166. }
  167. }
  168. /**
  169. * @api {POST} api/Sellervrorder/order_info 虚拟订单详情
  170. * @apiVersion 1.0.0
  171. * @apiGroup Sellervrorder
  172. *
  173. * @apiHeader {String} X-DS-KEY 卖家授权token
  174. *
  175. * @apiParam {String} order_id 订单id
  176. *
  177. * @apiSuccess {String} code 返回码,10000为成功
  178. * @apiSuccess {String} message 返回消息
  179. * @apiSuccess {Object} result 返回数据 (返回字段参考vrorder)
  180. */
  181. public function order_info() {
  182. $order_id = intval(input('param.order_id'));
  183. if ($order_id <= 0) {
  184. ds_json_encode(10001, lang('param_error'));
  185. }
  186. $vrorder_model = model('vrorder');
  187. $condition = array();
  188. $condition[] = array('order_id','=',$order_id);
  189. $condition[] = array('store_id','=',$this->store_info['store_id']);
  190. $order_info = $vrorder_model->getVrorderInfo($condition);
  191. if (empty($order_info) || $order_info['delete_state'] == ORDER_DEL_STATE_DROP) {
  192. ds_json_encode(10001, lang('store_order_none_exist'));
  193. }
  194. $order_list = array();
  195. $order_list[$order_id] = $order_info;
  196. //显示取消订单
  197. $order_info['if_cancel'] = $vrorder_model->getVrorderOperateState('buyer_cancel', $order_info);
  198. $order_info['goods_image_url'] = goods_cthumb($order_info['goods_image'], 240, $order_info['store_id']);
  199. $ownShopIds = model('store')->getOwnShopIds();
  200. $order_info['ownshop'] = in_array($order_info['store_id'], $ownShopIds);
  201. $order_info['vr_indate'] = $order_info['vr_indate'] ? date('Y-m-d', $order_info['vr_indate']) : '';
  202. $order_info['add_time'] = date('Y-m-d H:i:s', $order_info['add_time']);
  203. $order_info['payment_time'] = $order_info['payment_time'] ? date('Y-m-d H:i:s', $order_info['payment_time']) : '';
  204. $order_info['finnshed_time'] = $order_info['finnshed_time'] ? date('Y-m-d H:i:s', $order_info['finnshed_time']) : '';
  205. //取兑换码列表
  206. $vr_code_list = $vrorder_model->getShowVrordercodeList(array('order_id' => $order_info['order_id']));
  207. $order_info['code_list'] = $vr_code_list ? $vr_code_list : array();
  208. if($order_info['order_state']==ORDER_STATE_SUCCESS){
  209. if($order_info['virtual_type']==3){
  210. $order_info['vc_file_url']=goods_resource($order_info['virtual_content']);
  211. }else if($order_info['virtual_type']==1){
  212. $order_info['virtual_content']=explode('\r\n',$order_info['virtual_content']);
  213. }
  214. }else{
  215. $order_info['virtual_content']='';
  216. }
  217. ds_json_encode(10000, '', array('order_info' => $order_info));
  218. }
  219. }
  220. ?>