Order.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <?php
  2. namespace store\Admin;
  3. use Dever;
  4. class Order extends Core
  5. {
  6. # 获取概览数据
  7. public function getData()
  8. {
  9. # 待处理订单
  10. $where['status'] = 3;
  11. $where['source_type'] = 2;
  12. $where['source_id'] = $this->id;
  13. # 待处理订单
  14. $data['order_num'] = Dever::db('shop/buy_order')->getOrderNum($where);
  15. # 超时待处理订单:72小时
  16. $where['end_o'] = time() - 72*3600;
  17. $data['cs_order_num'] = Dever::db('shop/buy_order')->getOrderNum($where);
  18. # 超时待处理订单:72小时
  19. $where = array();
  20. $where['status'] = 4;
  21. $where['type'] = 2;
  22. $where['type_id'] = $this->id;
  23. $where['end_o'] = time() - 72*3600;
  24. $data['sh_order_num'] = Dever::db('shop/buy_order')->getOrderNum($where);
  25. return $data;
  26. }
  27. # 订单列表
  28. public function getList()
  29. {
  30. $data = Dever::load('mshop/lib/buy')->set(12, 1)->getList($this->id);
  31. $html = '';
  32. if ($data && $data['order']) {
  33. $out_status = Dever::db('shop/buy_order')->config['out_status'];
  34. $excel = Dever::input('excel', 1);
  35. if ($excel == 2) {
  36. Dever::load('store/admin/excel')->out($this->id, $this->user, $data['order']);
  37. die;
  38. return;
  39. }
  40. foreach ($data['order'] as $k => $v) {
  41. if ($v['ps_info']) {
  42. $ps_date = $v['ps_info']['cdate'];
  43. } else {
  44. $ps_date = '-';
  45. }
  46. $view = Dever::url('order_view?type=3&noprice=1&order_id=' . $v['id'] . '&cash=2&store_type=1', 'store');
  47. $send = Dever::url('order_send?id=' . $v['id'] . '&type=2', 'store');
  48. $button = '<a href="'.$view.'"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 layui-btn layui-btn-xs">查看详情</button></a>';
  49. if ($v['status'] < 5) {
  50. $print = Dever::url('admin/order.print?id=' . $v['id'] . '&type=2', 'store');
  51. $button .= '&nbsp;&nbsp;<a href="'.$print.'" id="print_'.$v['id'].'" target="_blank"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 layui-btn layui-btn-xs">打印备货单</button></a>';
  52. }
  53. if ($v['status'] == 3) {
  54. $button .= '&nbsp;&nbsp;<a href="javascript:;" id="send_'.$v['id'].'" onclick="fastEdit($(this), \''.$send.'\', \'配送发货\', \'\', 1)"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 layui-btn layui-btn-xs">配送发货</button></a>';
  55. }
  56. if ($v['status_name'] == '待确认收货') {
  57. $v['status_name'] = '已发货';
  58. }
  59. if ($v['refund_status'] == 2 && $v['status'] != 8) {
  60. $v['status_name'] .= '[申请报损中]';
  61. }
  62. $order = array();
  63. if ($v['parent_type'] == 2) {
  64. $order = Dever::db('shop/sell_order')->find($v['parent_order_id']);
  65. if ($order && $order['uid']) {
  66. if ($order['address_id']) {
  67. $order['address'] = Dever::load('passport/address')->getOne($order['uid'], $order['address_id']);
  68. $v['type_info']['name'] = $order['address']['contact'];
  69. } else {
  70. $user = Dever::db('passport/user')->find($order['uid']);
  71. $v['type_info']['name'] = $user['username'];
  72. }
  73. }
  74. } elseif ($v['parent_type'] == 3) {
  75. $order = Dever::db('agent/dh_order')->find($v['parent_order_id']);
  76. if ($order && $order['mid']) {
  77. if ($order['address_id']) {
  78. $order['address'] = Dever::load('agent/address')->getOne($order['mid'], $order['address_id']);
  79. $v['type_info']['name'] = $order['address']['contact'];
  80. } else {
  81. $user = Dever::db('agent/member')->find($order['mid']);
  82. $v['type_info']['name'] = $user['name'];
  83. }
  84. }
  85. }
  86. $v['out_status_name'] = $out_status[$v['source_out_status']];
  87. $dao_date = '-';
  88. if ($v['source_out_date']) {
  89. $dao_date = date('Y-m-d H:i', $v['source_out_date']);
  90. }
  91. //$html .= '<tr><td><input type="checkbox" name="mul_where_id[]" class="checkbox-checkall-list" lay-ignore value="'.$v['id'].'"/></td><td>'.$v['order_num'].'</td><td>'.$v['operdate'].'</td><td>'.$v['type_info']['name'].'</td><td>'.$ps_date.'</td><td>'.$v['num'].'</td><td>'.$v['status_name'].'</td><td>'.$v['out_status_name'].'</td><td>'.$dao_date.'</td><td>'.$button.'</td></tr>';
  92. $html .= '<tr><td>'.$v['order_num'].'</td><td>'.$v['operdate'].'</td><td>'.$v['type_info']['name'].'</td><td>'.$ps_date.'</td><td>'.$v['num'].'</td><td>'.$v['status_name'].'</td><td>'.$v['out_status_name'].'</td><td>'.$dao_date.'</td><td>'.$button.'</td></tr>';
  93. }
  94. }
  95. return $html;
  96. }
  97. # 获取列表页搜索信息
  98. public function getSearch()
  99. {
  100. $config = array
  101. (
  102. array('value' => '0', 'name' => '全部'),
  103. array('value' => 3, 'name' => '待发货'),
  104. array('value' => 4, 'name' => '已发货'),
  105. array('value' => '5,6', 'name' => '已到货'),
  106. array('value' => '7,8,11', 'name' => '已取消'),
  107. array('value' => 'refund', 'name' => '缺货与报损'),
  108. );
  109. $status = Dever::input('status');
  110. $html = '';
  111. foreach ($config as $k => $v) {
  112. $selected = '';
  113. if ((!$status && $k == 0) || $status == $v['value']) {
  114. $selected = 'selected=""';
  115. }
  116. $html .= '<option value="'.$v['value'].'" '.$selected.'>'.$v['name'].'</option>';
  117. }
  118. return $html;
  119. }
  120. # 获取列表页搜索信息
  121. public function getSearchOutStatus()
  122. {
  123. $config = array
  124. (
  125. array('value' => '0', 'name' => '全部'),
  126. array('value' => 1, 'name' => '未导出'),
  127. array('value' => 2, 'name' => '已导出'),
  128. );
  129. $status = Dever::input('source_out_status');
  130. $html = '';
  131. foreach ($config as $k => $v) {
  132. $selected = '';
  133. if ((!$status && $k == 0) || $status == $v['value']) {
  134. $selected = 'selected=""';
  135. }
  136. $html .= '<option value="'.$v['value'].'" '.$selected.'>'.$v['name'].'</option>';
  137. }
  138. return $html;
  139. }
  140. # 获取列表页搜索信息
  141. public function getService()
  142. {
  143. $service = Dever::db('shop/service')->select();
  144. $html = '';
  145. foreach ($service as $k => $v) {
  146. $selected = '';
  147. if ($k == 0) {
  148. $selected = 'selected=""';
  149. }
  150. $html .= '<option value="'.$v['id'].'" '.$selected.'>'.$v['name'].'</option>';
  151. }
  152. return $html;
  153. }
  154. # 获取基本信息
  155. public function getConfig()
  156. {
  157. $data['search'] = Dever::url('order', 'store');
  158. # 发货
  159. $data['send'] = Dever::url('admin/order.send', 'store');
  160. # 退款
  161. $data['tui'] = Dever::url('lib/buy.refund_apply_info_one_commit?json=1', 'mshop');
  162. # 导入物流单号
  163. $data['import'] = Dever::load('upload/import.url', 'store/admin/order.import', 10);
  164. return $data;
  165. }
  166. # 导入物流单号
  167. public function import($file)
  168. {
  169. $file = Dever::local($file);
  170. $data = Dever::excelImport($file, 0);
  171. if ($data) {
  172. $psinfo = array();
  173. foreach ($data as $k => $v) {
  174. if ($k == 2) {
  175. $order_num = $v['A'];
  176. if ($order_num) {
  177. $order = Dever::db('shop/buy_order')->find(array('order_num' => $order_num));
  178. if ($order && $order['status'] == 3) {
  179. if (!isset($psinfo[$order['id']])) {
  180. $psinfo[$order['id']] = array();
  181. }
  182. $psinfo[$order['id']][] = array($v['B'], $v['C'], $v['D']);
  183. }
  184. }
  185. }
  186. }
  187. if ($psinfo) {
  188. foreach ($psinfo as $k => $v) {
  189. $update = array();
  190. $update['order_id'] = $k;
  191. $service = array();
  192. foreach ($v as $k1 => $v1) {
  193. if ($v1[2] && strstr($v1[2], '-')) {
  194. $update['cdate'] = Dever::maketime($v1[2]);
  195. } else {
  196. $update['cdate'] = time();
  197. }
  198. $service_info = Dever::db('shop/service')->find(array('name' => $v1[1], 'clear' => true));
  199. if (!$service_info) {
  200. $service_id = Dever::db('shop/service')->insert(array('name' => $v1[1], 'type' => 1));
  201. } else {
  202. $service_id = $service_info['id'];
  203. }
  204. $service[] = array
  205. (
  206. 'order' => $k1,
  207. 'service_id' => $service_id,
  208. 'order_num' => $v1[0],
  209. );
  210. }
  211. if ($service) {
  212. $update['service'] = $service;
  213. }
  214. $this->send_action($update);
  215. }
  216. }
  217. }
  218. }
  219. # 发货
  220. public function send_api()
  221. {
  222. $input = Dever::input();
  223. $service = array();
  224. $order_id = Dever::input('update_where_id');
  225. foreach ($input as $k => $v) {
  226. if (strpos($k, '_c_') !== false) {
  227. if ($v == 'null') {
  228. $v = '';
  229. }
  230. $temp = explode('_c_', $k);
  231. $k = str_replace('update_', '', $temp[0]);
  232. if (!isset($c[$k])) {
  233. $c[$k] = array();
  234. }
  235. if (strpos($temp[1], '_i_') !== false) {
  236. $temp = explode('_i_', $temp[1]);
  237. if (!isset($c[$k][$temp[1]])) {
  238. $c[$k][$temp[1]] = 0;
  239. } else {
  240. $c[$k][$temp[1]]++;
  241. }
  242. $num = $c[$k][$temp[1]];
  243. $service[$k][$num][$temp[1]] = $v;
  244. }
  245. }
  246. }
  247. $update = array();
  248. if ($service) {
  249. $update = $service;
  250. }
  251. $update['order_id'] = $order_id;
  252. $update['cdate'] = $input['update_cdate'];
  253. /*
  254. $update['service_id'] = $input['update_service_id'];
  255. $update['order_num'] = $input['update_order_num'];
  256. $update['num'] = $input['update_num'];
  257. $update['phy'] = $input['update_phy'];
  258. $update['dby'] = $input['update_dby'];
  259. $update['zl'] = $input['update_zl'];
  260. $update['tj'] = $input['update_tj'];
  261. $update['price'] = $input['update_price'];
  262. */
  263. return $this->send_action($update);
  264. }
  265. private function send_action($update = array())
  266. {
  267. $info = Dever::db('shop/buy_order_ps')->find(array('order_id' => $update['order_id']));
  268. if (isset($update['service'])) {
  269. $update['service'] = Dever::array_encode($update['service']);
  270. }
  271. if ($info) {
  272. $update['where_id'] = $info['id'];
  273. Dever::db('shop/buy_order_ps')->update($update);
  274. } else {
  275. Dever::db('shop/buy_order_ps')->insert($update);
  276. }
  277. Dever::db('shop/buy_order')->update(array('status' => 4, 'where_id' => $update['order_id'],'fadate'=>time()));
  278. # 检测是否是关联订单
  279. $order = Dever::db('shop/buy_order')->find($update['order_id']);
  280. if ($order && $order['parent_type'] > 1) {
  281. $data = Dever::db('shop/buy_order')->find(array('status' => 3, 'parent_type' => $order['parent_type'], 'parent_order_id' => $order['parent_order_id']));
  282. if (!$data) {
  283. # 更改关联订单状态
  284. if ($order['parent_type'] == 2) {
  285. Dever::db('shop/sell_order')->update(array('where_id' => $order['parent_order_id'], 'status' => 4));
  286. $data = Dever::db('shop/buy_order')->getDataToId(array('parent_type' => $order['parent_type'], 'parent_order_id' => $order['parent_order_id']));
  287. $data = array_keys($data);
  288. $ps_info = Dever::db('shop/buy_order_ps')->getData(array('order_id' => $data));
  289. if ($ps_info) {
  290. $sell_order = array('id' => $order['parent_order_id']);
  291. foreach ($ps_info as $k => $v) {
  292. $v['service'] = Dever::array_decode($v['service']);
  293. foreach ($v['service'] as $k1 => $v1) {
  294. if (isset($v1['order_num']) && $v1['order_num']) {
  295. Dever::load('shop/lib/sell')->updatePs($sell_order, 2, $v1['service_id'], $v1['order_num'], $v['cdate']);
  296. }
  297. }
  298. }
  299. }
  300. } elseif ($order['parent_type'] == 3) {
  301. Dever::db('agent/dh_order')->update(array('where_id' => $order['parent_order_id'], 'status' => 4));
  302. $data = Dever::db('shop/buy_order')->getDataToId(array('parent_type' => $order['parent_type'], 'parent_order_id' => $order['parent_order_id']));
  303. $data = array_keys($data);
  304. $ps_info = Dever::db('shop/buy_order_ps')->getData(array('order_id' => $data));
  305. if ($ps_info) {
  306. $dh_order = array('id' => $order['parent_order_id']);
  307. foreach ($ps_info as $k => $v) {
  308. $v['service'] = Dever::array_decode($v['service']);
  309. foreach ($v['service'] as $k1 => $v1) {
  310. if (isset($v1['order_num']) && $v1['order_num']) {
  311. Dever::load('agent/lib/dhorder')->updatePs($dh_order, 2, $v1['service_id'], $v1['order_num'], $v['cdate']);
  312. }
  313. }
  314. }
  315. }
  316. }
  317. }
  318. }
  319. return 'reload';
  320. }
  321. public function print_api()
  322. {
  323. return Dever::load('mshop/lib/buy')->printer($this->user);
  324. }
  325. # 获取报损信息
  326. public function refund()
  327. {
  328. $data = Dever::load('mshop/lib/buy')->refund_apply_info_one_info();
  329. if (isset($data['num'])) {
  330. $data['tui_price_info'] = 'x' . $data['num'];
  331. } else {
  332. $data['tui_price_info'] = '0';
  333. }
  334. return $data;
  335. }
  336. }