Sellervrorder.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <?php
  2. /*
  3. * 虚拟订单
  4. */
  5. namespace app\home\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. /**
  9. * ============================================================================
  10. * DSMall多用户商城
  11. * ============================================================================
  12. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  13. * 网站地址: http://www.csdeshang.com
  14. * ----------------------------------------------------------------------------
  15. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  16. * 不允许对程序代码以任何形式任何目的的再发布。
  17. * ============================================================================
  18. * 控制器
  19. */
  20. class Sellervrorder extends BaseSeller {
  21. public function initialize() {
  22. parent::initialize();
  23. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellervrorder.lang.php');
  24. }
  25. /**
  26. * 虚拟订单列表
  27. *
  28. */
  29. public function index() {
  30. $vrorder_model = model('vrorder');
  31. $condition = array();
  32. $condition[] = array('store_id', '=', session('store_id'));
  33. $order_sn = input('get.order_sn');
  34. if ($order_sn != '') {
  35. $condition[] = array('order_sn', '=', $order_sn);
  36. }
  37. $buyer_name = input('get.buyer_name');
  38. if ($buyer_name != '') {
  39. $condition[] = array('buyer_name', '=', $buyer_name);
  40. }
  41. $allow_state_array = array('state_new', 'state_pay', 'state_success', 'state_cancel');
  42. $state_type = input('param.state_type');
  43. if (in_array($state_type, $allow_state_array)) {
  44. $condition[] = array('order_state', '=', str_replace($allow_state_array, array(ORDER_STATE_NEW, ORDER_STATE_PAY, ORDER_STATE_SUCCESS, ORDER_STATE_CANCEL), $state_type));
  45. } else {
  46. $state_type = 'store_order';
  47. }
  48. $query_start_date = input('get.query_start_date');
  49. $query_end_date = input('get.query_end_date');
  50. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
  51. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
  52. $start_unixtime = $if_start_date ? strtotime($query_end_date) : null;
  53. $end_unixtime = $if_end_date ? (strtotime($query_start_date)+86399) : null;
  54. if ($start_unixtime) {
  55. $condition[] = array('add_time', '>=', $start_unixtime);
  56. }
  57. if ($end_unixtime) {
  58. $condition[] = array('add_time', '<=', $end_unixtime);
  59. }
  60. $skip_off = input('get.skip_off');
  61. if ($skip_off == 1) {
  62. $condition[] = array('order_state', '<>', ORDER_STATE_CANCEL);
  63. }
  64. $order_list = $vrorder_model->getVrorderList($condition, 20, '*', 'order_id desc');
  65. View::assign('show_page', $vrorder_model->page_info->render());
  66. foreach ($order_list as $key => $order) {
  67. //显示取消订单
  68. $order_list[$key]['if_cancel'] = $vrorder_model->getVrorderOperateState('buyer_cancel', $order);
  69. //追加返回买家信息
  70. $order_list[$key]['extend_member'] = model('member')->getMemberInfoByID($order['buyer_id']);
  71. }
  72. View::assign('order_list', $order_list);
  73. /* 设置卖家当前菜单 */
  74. $this->setSellerCurMenu('sellervrorder');
  75. /* 设置卖家当前栏目 */
  76. $this->setSellerCurItem($state_type);
  77. return View::fetch($this->template_dir . 'index');
  78. }
  79. /**
  80. * 卖家订单详情
  81. *
  82. */
  83. public function show_order() {
  84. $order_id = intval(input('param.order_id'));
  85. if ($order_id <= 0) {
  86. $this->error(lang('param_error'));
  87. }
  88. $vrorder_model = model('vrorder');
  89. $condition = array();
  90. $condition[] = array('order_id','=',$order_id);
  91. $condition[] = array('store_id','=',session('store_id'));
  92. $order_info = $vrorder_model->getVrorderInfo($condition);
  93. if (empty($order_info)) {
  94. $this->error(lang('store_order_none_exist'));
  95. }
  96. //取兑换码列表
  97. $vr_code_list = $vrorder_model->getShowVrordercodeList(array('order_id' => $order_info['order_id']));
  98. $order_info['extend_vr_order_code'] = $vr_code_list;
  99. //显示取消订单
  100. $order_info['if_cancel'] = $vrorder_model->getVrorderOperateState('buyer_cancel', $order_info);
  101. //显示订单进行步骤
  102. $order_info['step_list'] = $vrorder_model->getVrorderStep($order_info);
  103. //显示系统自动取消订单日期
  104. if ($order_info['order_state'] == ORDER_STATE_NEW) {
  105. $order_info['order_cancel_day'] = $order_info['add_time'] + config('ds_config.order_auto_cancel_day') * 24 * 3600;
  106. }
  107. if($order_info['virtual_type']==1){
  108. $order_info['virtual_content']=explode('\r\n',$order_info['virtual_content']);
  109. }
  110. View::assign('order_info', $order_info);
  111. $this->setSellerCurMenu('sellervrorder');
  112. $this->setSellerCurItem('store_order');
  113. return View::fetch($this->template_dir . 'show_order');
  114. }
  115. /**
  116. * 卖家订单状态操作
  117. *
  118. */
  119. public function change_state() {
  120. $vrorder_model = model('vrorder');
  121. $condition = array();
  122. $condition[] = array('order_id','=',intval(input('param.order_id')));
  123. $condition[] = array('store_id','=',session('store_id'));
  124. $order_info = $vrorder_model->getVrorderInfo($condition);
  125. $state_type = input('param.state_type');
  126. if ($state_type == 'order_cancel') {
  127. $result = $this->_order_cancel($order_info, input('post.'));
  128. }
  129. if (!isset($result['code'])) {
  130. ds_json_encode(10001, lang('error'));
  131. } else {
  132. ds_json_encode(10000, $result['msg']);
  133. }
  134. }
  135. /**
  136. * 取消订单
  137. * @param arrty $order_info
  138. * @param arrty $post
  139. * @throws Exception
  140. */
  141. private function _order_cancel($order_info, $post) {
  142. if (!request()->isPost()) {
  143. View::assign('order_id', $order_info['order_id']);
  144. View::assign('order_info', $order_info);
  145. echo View::fetch($this->template_dir . 'cancel');
  146. exit();
  147. } else {
  148. $vrorder_model = model('vrorder');
  149. $logic_vrorder = model('vrorder', 'logic');
  150. $if_allow = $vrorder_model->getVrorderOperateState('store_cancel', $order_info);
  151. if (!$if_allow) {
  152. return ds_callback(false, lang('have_right_operate'));
  153. }
  154. $msg = $post['state_info1'] != '' ? $post['state_info1'] : $post['state_info'];
  155. return $logic_vrorder->changeOrderStateCancel($order_info, 'seller', $msg);
  156. }
  157. }
  158. public function exchange() {
  159. $data = $this->_exchange();
  160. exit(json_encode($data));
  161. }
  162. /**
  163. * 兑换码消费
  164. */
  165. private function _exchange() {
  166. if (input('param.submit_exchange') == 'ok') {
  167. if (!preg_match('/^[a-zA-Z0-9]{15,18}$/', input('get.vr_code'))) {
  168. return array('error' => lang('exchange_code_format_error'));
  169. }
  170. $vrorder_model = model('vrorder');
  171. $vr_code_info = $vrorder_model->getVrordercodeInfo(array('vr_code' => input('get.vr_code')));
  172. if (empty($vr_code_info) || $vr_code_info['store_id'] != session('store_id')) {
  173. return array('error' => lang('exchange_code_not_exist'));
  174. }
  175. if ($vr_code_info['vr_state'] == '1') {
  176. return array('error' => lang('exchange_code_been_used'));
  177. }
  178. if ($vr_code_info['vr_indate'] < TIMESTAMP) {
  179. return array('error' => lang('exchange_code_expired') . date('Y-m-d H:i:s', $vr_code_info['vr_indate']));
  180. }
  181. if ($vr_code_info['refund_lock'] > 0) {//退款锁定状态:0为正常,1为锁定(待审核),2为同意
  182. return array('error' => lang('exchange_code_been_applied_refund'));
  183. }
  184. //更新兑换码状态
  185. $update = array();
  186. $update['vr_state'] = 1;
  187. $update['vr_usetime'] = TIMESTAMP;
  188. $update = $vrorder_model->editVrorderCode($update, array('vr_code' => input('get.vr_code')));
  189. //如果全部兑换完成,更新订单状态
  190. model('vrorder', 'logic')->changeOrderStateSuccess($vr_code_info['order_id']);
  191. if ($update) {
  192. //取得返回信息
  193. $order_info = $vrorder_model->getVrorderInfo(array('order_id' => $vr_code_info['order_id']));
  194. if ($order_info['use_state'] == '0') {
  195. $vrorder_model->editVrorder(array('use_state' => 1), array('order_id' => $vr_code_info['order_id']));
  196. }
  197. $order_info['img_240'] = goods_thumb($order_info, 240);
  198. $order_info['goods_url'] = (string) url('Goods/index', ['goods_id' => $order_info['goods_id']]);
  199. $order_info['order_url'] = (string) url('Sellervrorder/show_order', ['order_id' => $order_info['order_id']]);
  200. return array('error' => '', 'data' => $order_info);
  201. }
  202. } else {
  203. $state_type = input('state_type');
  204. ;
  205. /* 设置卖家当前菜单 */
  206. $this->setSellerCurMenu('sellervrorder');
  207. /* 设置卖家当前栏目 */
  208. $this->setSellerCurItem($state_type);
  209. echo View::fetch($this->template_dir . 'exchange');
  210. exit;
  211. }
  212. }
  213. /**
  214. * 栏目菜单
  215. */
  216. function getSellerItemList() {
  217. $menu_array = array(
  218. array(
  219. 'name' => 'store_order',
  220. 'text' => lang('ds_member_path_all_order'),
  221. 'url' => (string) url('Sellervrorder/index'),
  222. ),
  223. array(
  224. 'name' => 'state_new',
  225. 'text' => lang('ds_member_path_wait_pay'),
  226. 'url' => (string) url('Sellervrorder/index', ['state_type' => 'state_new']),
  227. ),
  228. array(
  229. 'name' => 'state_pay',
  230. 'text' => lang('payment_been'),
  231. 'url' => (string) url('Sellervrorder/index', ['state_type' => 'state_pay']),
  232. ),
  233. array(
  234. 'name' => 'state_success',
  235. 'text' => lang('ds_member_path_finished'),
  236. 'url' => (string) url('Sellervrorder/index', ['state_type' => 'state_success']),
  237. ),
  238. array(
  239. 'name' => 'state_cancel',
  240. 'text' => lang('ds_member_path_canceled'),
  241. 'url' => (string) url('Sellervrorder/index', ['state_type' => 'state_cancel']),
  242. ),
  243. );
  244. if (request()->action() === 'exchange') {
  245. $menu_array[] = array(
  246. 'name' => 'exchange',
  247. 'text' => lang('exchange_code'),
  248. 'url' => (string) url('Sellervrorder/exchange'),
  249. );
  250. }
  251. return $menu_array;
  252. }
  253. }