Sellerstoreorder.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?php
  2. /*
  3. * 虚拟订单
  4. */
  5. namespace app\home\controller;
  6. use think\facade\Db;
  7. use think\facade\View;
  8. use think\facade\Lang;
  9. /**
  10. * ============================================================================
  11. * DSMall多用户商城
  12. * ============================================================================
  13. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  14. * 网站地址: http://www.csdeshang.com
  15. * ----------------------------------------------------------------------------
  16. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  17. * 不允许对程序代码以任何形式任何目的的再发布。
  18. * ============================================================================
  19. * 控制器
  20. */
  21. class Sellerstoreorder extends BaseSeller
  22. {
  23. public function initialize()
  24. {
  25. parent::initialize();
  26. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellervrorder.lang.php');
  27. }
  28. /**
  29. * 订单列表
  30. *
  31. */
  32. public function index()
  33. {
  34. //上级店铺id
  35. $store_id = session('store_id');
  36. $store_arr = Db::name('store')->field('store_id,store_name')
  37. ->where('p_id', $store_id)
  38. ->whereOr('store_id', $store_id)
  39. ->select();
  40. View::assign('store_arr', $store_arr);
  41. $store_ids = $store_arr->column('store_id');
  42. $store_column = [];
  43. foreach ($store_arr as $store) {
  44. $store_column[$store['store_id']] = $store['store_name'];
  45. }
  46. //店铺搜索条件
  47. $store_id_input = input('param.store_id', 0);
  48. if (!empty($store_id_input)) {
  49. if (in_array($store_id_input, $store_ids)) {
  50. $store_ids = [$store_id_input];
  51. } else {
  52. $store_ids = [0];
  53. }
  54. }
  55. View::assign('store_id_input', $store_id_input);
  56. $model = model('StoreOrder');
  57. $condition = [];
  58. $condition[] = ['store_id', 'in', $store_ids];
  59. $order_sn = input('get.order_sn');
  60. if ($order_sn != '') {
  61. $condition[] = ['order_sn', '=', $order_sn];
  62. }
  63. $buyer_name = input('get.buyer_name');
  64. if ($buyer_name != '') {
  65. $condition[] = ['buyer_name', '=', $buyer_name];
  66. }
  67. $allow_state_array = ['state_new', 'state_success', 'state_cancel'];
  68. $state_type = input('param.state_type');
  69. if (in_array($state_type, $allow_state_array)) {
  70. $condition[] = ['order_state', '=', str_replace($allow_state_array, [ORDER_STATE_NEW, ORDER_STATE_SUCCESS, ORDER_STATE_CANCEL], $state_type)];
  71. $condition[] = ['is_refund', '=', 2];
  72. } else {
  73. $state_type = 'store_order';
  74. }
  75. $query_start_date = input('get.query_start_date');
  76. $query_end_date = input('get.query_end_date');
  77. if ($query_start_date) {
  78. $condition[] = ['add_time', '>=', strtotime($query_start_date)];
  79. }
  80. if ($query_end_date) {
  81. $condition[] = ['add_time', '<=', strtotime($query_end_date)];
  82. }
  83. $is_refund = input('param.is_refund');
  84. if ($is_refund == 1) {
  85. $state_type = 'order_refund';
  86. $condition[] = ['is_refund', '=', 1];
  87. }
  88. $order_list = $model->getOrderList($condition, 20, '*', 'id desc', 0, ['member']);
  89. View::assign('show_page', $model->page_info->render());
  90. foreach ($order_list as $key => $order) {
  91. //店铺名称
  92. $order_list[$key]['store_name'] = $store_column[$order['store_id']];
  93. }
  94. View::assign('order_list', $order_list);
  95. /* 设置卖家当前菜单 */
  96. $this->setSellerCurMenu('sellerstoreorder');
  97. /* 设置卖家当前栏目 */
  98. $this->setSellerCurItem($state_type);
  99. return View::fetch($this->template_dir . 'index');
  100. }
  101. /**
  102. * 订单详情
  103. *
  104. */
  105. public function show_order()
  106. {
  107. $order_id = intval(input('param.id'));
  108. if ($order_id <= 0) {
  109. $this->error(lang('miss_order_number'));
  110. }
  111. $order_model = model('StoreOrder');
  112. $order_info = $order_model->getOrderInfo(['id' => $order_id], ['store', 'member']);
  113. $order_info['deduction_amount'] = number_format($order_info['deduction_amount'], 2);
  114. View::assign('order_info', $order_info);
  115. View::assign('order_info', $order_info);
  116. $this->setSellerCurMenu('sellerstoreorder');
  117. $this->setSellerCurItem('store_order');
  118. return View::fetch($this->template_dir . 'show_order');
  119. }
  120. /**
  121. * 订单状态操作
  122. *
  123. */
  124. public function change_state()
  125. {
  126. $model = model('StoreOrder');
  127. $condition = [];
  128. $condition[] = ['id', '=', intval(input('param.id'))];
  129. $condition[] = ['store_id', '=', session('store_id')];
  130. $state_type = input('param.state_type');
  131. if ($state_type == 'order_cancel') {
  132. $model->where($condition)->update(['order_state' => 0]);
  133. }
  134. ds_json_encode(10000, '操作成功');
  135. }
  136. /**
  137. * 栏目菜单
  138. */
  139. function getSellerItemList()
  140. {
  141. $menu_array = [
  142. [
  143. 'name' => 'store_order',
  144. 'text' => lang('ds_member_path_all_order'),
  145. 'url' => (string)url('Sellerstoreorder/index'),
  146. ],
  147. [
  148. 'name' => 'state_new',
  149. 'text' => lang('ds_member_path_wait_pay'),
  150. 'url' => (string)url('Sellerstoreorder/index', ['state_type' => 'state_new']),
  151. ],
  152. [
  153. 'name' => 'state_success',
  154. 'text' => lang('ds_member_path_finished'),
  155. 'url' => (string)url('Sellerstoreorder/index', ['state_type' => 'state_success']),
  156. ],
  157. [
  158. 'name' => 'state_cancel',
  159. 'text' => lang('ds_member_path_canceled'),
  160. 'url' => (string)url('Sellerstoreorder/index', ['state_type' => 'state_cancel']),
  161. ],
  162. [
  163. 'name' => 'order_refund',
  164. 'text' => lang('已退款'),
  165. 'url' => (string)url('Sellerstoreorder/index', ['is_refund' => '1']),
  166. ],
  167. ];
  168. return $menu_array;
  169. }
  170. public function export()
  171. {
  172. //上级店铺id
  173. $store_id = session('store_id');
  174. $store_arr = Db::name('store')->field('store_id,store_name')
  175. ->where('p_id', $store_id)
  176. ->whereOr('store_id', $store_id)
  177. ->select();
  178. $store_ids = $store_arr->column('store_id');
  179. $store_column = [];
  180. foreach ($store_arr as $store) {
  181. $store_column[$store['store_id']] = $store['store_name'];
  182. }
  183. //店铺搜索条件
  184. $store_id_input = input('param.store_id', 0);
  185. if (!empty($store_id_input)) {
  186. if (in_array($store_id_input, $store_ids)) {
  187. $store_ids = [$store_id_input];
  188. } else {
  189. $store_ids = [0];
  190. }
  191. }
  192. $model = model('StoreOrder');
  193. $condition = [];
  194. $condition[] = ['store_id', 'in', $store_ids];
  195. $ids = input('get.ids');
  196. if (!empty($ids)) {
  197. $condition[] = ['id', 'in', explode(',', $ids)];
  198. }
  199. $order_sn = input('get.order_sn');
  200. if ($order_sn != '') {
  201. $condition[] = ['order_sn', '=', $order_sn];
  202. }
  203. $buyer_name = input('get.buyer_name');
  204. if ($buyer_name != '') {
  205. $condition[] = ['buyer_name', '=', $buyer_name];
  206. }
  207. $allow_state_array = ['state_new', 'state_success', 'state_cancel'];
  208. $state_type = input('param.state_type');
  209. if (in_array($state_type, $allow_state_array)) {
  210. $condition[] = ['order_state', '=', str_replace($allow_state_array, [ORDER_STATE_NEW, ORDER_STATE_SUCCESS, ORDER_STATE_CANCEL], $state_type)];
  211. $condition[] = ['is_refund', '=', 2];
  212. }
  213. $query_start_date = input('get.query_start_date');
  214. $query_end_date = input('get.query_end_date');
  215. if ($query_start_date) {
  216. $condition[] = ['add_time', '>=', strtotime($query_start_date)];
  217. }
  218. if ($query_end_date) {
  219. $condition[] = ['add_time', '<=', strtotime($query_end_date)];
  220. }
  221. $is_refund = input('param.is_refund');
  222. if ($is_refund == 1) {
  223. $condition[] = ['is_refund', '=', 1];
  224. }
  225. $order_list = $model->getOrderList($condition, 0, '*', 'id desc', 0, ['member']);
  226. foreach ($order_list as $key => $order) {
  227. //店铺名称
  228. $order_list[$key]['store_name'] = $store_column[$order['store_id']];
  229. }
  230. $this->createExcel($order_list);
  231. }
  232. /**
  233. * 生成excel
  234. *
  235. * @param array $data
  236. */
  237. private function createExcel($data = [])
  238. {
  239. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/export.lang.php');
  240. $excel_obj = new \excel\Excel();
  241. $excel_data = [];
  242. //设置样式
  243. $excel_obj->setStyle(['id' => 's_title', 'Font' => ['FontName' => '宋体', 'Size' => '12', 'Bold' => '1']]);
  244. //header
  245. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_no')];
  246. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_store')];
  247. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_buyer')];
  248. $excel_data[0][] = ['styleid' => 's_title', 'data' => '手机号'];
  249. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_xtimd')];
  250. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_count')];
  251. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_paytype')];
  252. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_state')];
  253. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_storeid')];
  254. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_buyerid')];
  255. //data
  256. foreach ((array)$data as $k => $v) {
  257. $tmp = [];
  258. $tmp[] = ['data' => $v['order_sn']];
  259. $tmp[] = ['data' => $v['store_name']];
  260. $tmp[] = ['data' => $v['buyer_name']];
  261. $tmp[] = ['data' => $v['extend_member']['member_mobile']];
  262. $tmp[] = ['data' => $v['add_time']];
  263. $tmp[] = ['format' => 'Number', 'data' => ds_price_format($v['order_amount'])];
  264. $tmp[] = ['data' => get_order_payment_name($v['payment_code'])];
  265. $tmp[] = ['data' => get_order_state($v)];
  266. $tmp[] = ['data' => $v['store_id']];
  267. $tmp[] = ['data' => $v['buyer_id']];
  268. $excel_data[] = $tmp;
  269. }
  270. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  271. $excel_obj->addArray($excel_data);
  272. $excel_obj->addWorksheet($excel_obj->charset(lang('exp_od_order'), CHARSET));
  273. $excel_obj->generateXML($excel_obj->charset(lang('exp_od_order'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
  274. }
  275. }