Sellerdeliverset.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <?php
  2. /*
  3. * 发货设置
  4. */
  5. namespace app\home\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. use think\facade\Db;
  9. /**
  10. *
  11. *
  12. * ----------------------------------------------------------------------------
  13. *
  14. * 控制器
  15. */
  16. class Sellerdeliverset extends BaseSeller
  17. {
  18. public function initialize()
  19. {
  20. parent::initialize();
  21. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerdeliver.lang.php');
  22. }
  23. /**
  24. * 发货地址列表
  25. */
  26. public function index()
  27. {
  28. $daddress_model = model('daddress');
  29. $condition = array();
  30. $condition[] = array('store_id', '=', session('store_id'));
  31. $address_list = $daddress_model->getAddressList($condition, '*', '', 20);
  32. View::assign('address_list', $address_list);
  33. /* 设置卖家当前菜单 */
  34. $this->setSellerCurMenu('sellerdeliverset');
  35. /* 设置卖家当前栏目 */
  36. $this->setSellerCurItem('daddress');
  37. return View::fetch($this->template_dir . 'index');
  38. }
  39. /**
  40. * 新增/编辑发货地址
  41. */
  42. public function daddress_add()
  43. {
  44. $address_id = intval(input('param.address_id'));
  45. if ($address_id > 0) {
  46. $daddress_mod = model('daddress');
  47. //编辑
  48. if (!request()->isPost()) {
  49. $address_info = $daddress_mod->getAddressInfo(array('daddress_id' => $address_id, 'store_id' => session('store_id')));
  50. View::assign('address_info', $address_info);
  51. return View::fetch($this->template_dir . 'daddress_add');
  52. } else {
  53. $data = array(
  54. 'seller_name' => input('post.seller_name'),
  55. 'area_id' => input('post.area_id'),
  56. 'city_id' => input('post.city_id'),
  57. 'area_info' => input('post.region'),
  58. 'daddress_detail' => input('post.address'),
  59. 'daddress_telphone' => input('post.telphone'),
  60. 'daddress_company' => input('post.company'),
  61. );
  62. //验证数据 BEGIN
  63. $sellerdeliverset_validate = ds_validate('sellerdeliverset');
  64. if (!$sellerdeliverset_validate->scene('daddress_add')->check($data)) {
  65. ds_json_encode(10001, $sellerdeliverset_validate->getError());
  66. }
  67. //验证数据 END
  68. $result = $daddress_mod->editDaddress($data, array('daddress_id' => $address_id, 'store_id' => session('store_id')));
  69. if ($result) {
  70. ds_json_encode(10000, lang('ds_common_op_succ'));
  71. } else {
  72. ds_json_encode(10001, lang('store_daddress_modify_fail'));
  73. }
  74. }
  75. } else {
  76. //新增
  77. if (!request()->isPost()) {
  78. $address_info = array(
  79. 'daddress_id' => '', 'city_id' => '1', 'area_id' => '1', 'seller_name' => '',
  80. 'area_info' => '', 'daddress_detail' => '', 'daddress_telphone' => '', 'daddress_company' => '',
  81. );
  82. View::assign('address_info', $address_info);
  83. return View::fetch($this->template_dir . 'daddress_add');
  84. } else {
  85. $data = array(
  86. 'store_id' => session('store_id'),
  87. 'seller_name' => input('post.seller_name'),
  88. 'area_id' => input('post.area_id'),
  89. 'city_id' => input('post.city_id'),
  90. 'area_info' => input('post.region'),
  91. 'daddress_detail' => input('post.address'),
  92. 'daddress_telphone' => input('post.telphone'),
  93. 'daddress_company' => input('post.company'),
  94. );
  95. //验证数据 BEGIN
  96. $sellerdeliverset_validate = ds_validate('sellerdeliverset');
  97. if (!$sellerdeliverset_validate->scene('daddress_add')->check($data)) {
  98. ds_json_encode(10001, $sellerdeliverset_validate->getError());
  99. }
  100. //验证数据 END
  101. $result = Db::name('daddress')->insertGetId($data);
  102. if ($result) {
  103. ds_json_encode(10000, lang('ds_common_op_succ'));
  104. } else {
  105. ds_json_encode(10001, lang('store_daddress_add_fail'));
  106. }
  107. }
  108. }
  109. }
  110. /**
  111. * 删除发货地址
  112. */
  113. public function daddress_del()
  114. {
  115. $address_id = intval(input('param.address_id'));
  116. if ($address_id <= 0) {
  117. ds_json_encode(10001, lang('store_daddress_del_fail'));
  118. }
  119. $condition = array();
  120. $condition[] = array('daddress_id', '=', $address_id);
  121. $condition[] = array('store_id', '=', session('store_id'));
  122. $delete = model('daddress')->delDaddress($condition);
  123. if ($delete) {
  124. ds_json_encode(10000, lang('store_daddress_del_succ'));
  125. } else {
  126. ds_json_encode(10001, lang('store_daddress_del_fail'));
  127. }
  128. }
  129. /**
  130. * 设置默认发货地址
  131. */
  132. public function daddress_default_set()
  133. {
  134. $address_id = intval(input('get.address_id'));
  135. if ($address_id <= 0)
  136. return false;
  137. $condition = array();
  138. $condition[] = array('store_id', '=', session('store_id'));
  139. $update = model('daddress')->editDaddress(array('daddress_isdefault' => 0), $condition);
  140. $condition[] = array('daddress_id', '=', $address_id);
  141. $update = model('daddress')->editDaddress(array('daddress_isdefault' => 1), $condition);
  142. }
  143. public function express()
  144. {
  145. $storeextend_model = model('storeextend');
  146. if (!request()->isPost()) {
  147. $express_list = rkcache('express', true);
  148. //取得店铺启用的快递公司ID
  149. $express_select = ds_getvalue_byname('storeextend', 'store_id', session('store_id'), 'express');
  150. if (!is_null($express_select)) {
  151. $express_select = explode(',', $express_select);
  152. } else {
  153. $express_select = array();
  154. }
  155. View::assign('express_select', $express_select);
  156. //页面输出
  157. View::assign('express_list', $express_list);
  158. /* 设置卖家当前菜单 */
  159. $this->setSellerCurMenu('sellerdeliverset');
  160. /* 设置卖家当前栏目 */
  161. $this->setSellerCurItem('express');
  162. return View::fetch($this->template_dir . 'express');
  163. } else {
  164. $data['store_id'] = session('store_id');
  165. $cexpress_array = input('post.cexpress/a'); #获取数组
  166. if (!empty($cexpress_array)) {
  167. $data['express'] = implode(',', $cexpress_array);
  168. } else {
  169. $data['express'] = '';
  170. }
  171. $condition = array();
  172. $condition[] = array('store_id', '=', session('store_id'));
  173. if (!$storeextend_model->getStoreextendInfo($condition)) {
  174. $result = $storeextend_model->addStoreextend($data);
  175. } else {
  176. $result = $storeextend_model->editStoreextend($data, $condition);
  177. }
  178. if ($result) {
  179. ds_json_encode('10000', lang('ds_common_save_succ'));
  180. } else {
  181. ds_json_encode('10001', lang('ds_common_save_fail'));
  182. }
  183. }
  184. }
  185. /**
  186. * 免运费额度设置
  187. */
  188. public function free_freight()
  189. {
  190. if (!request()->isPost()) {
  191. View::assign('store_free_price', $this->store_info['store_free_price']);
  192. View::assign('store_free_time', $this->store_info['store_free_time']);
  193. /* 设置卖家当前菜单 */
  194. $this->setSellerCurMenu('sellerdeliverset');
  195. /* 设置卖家当前栏目 */
  196. $this->setSellerCurItem('free_freight');
  197. return View::fetch($this->template_dir . 'free_freight');
  198. } else {
  199. $store_model = model('store');
  200. $store_free_price = floatval(abs(input('post.store_free_price')));
  201. $store_free_time = input('post.store_free_time');
  202. $store_model->editStore(array(
  203. 'store_free_price' => $store_free_price,
  204. 'store_free_time' => $store_free_time
  205. ), array('store_id' => session('store_id')));
  206. ds_json_encode(10000, lang('ds_common_save_succ'));
  207. }
  208. }
  209. /**
  210. * 电子面单
  211. */
  212. public function eorder_set()
  213. {
  214. if (!request()->isPost()) {
  215. View::assign('store_info', $this->store_info);
  216. /* 设置卖家当前菜单 */
  217. $this->setSellerCurMenu('sellerdeliverset');
  218. /* 设置卖家当前栏目 */
  219. $this->setSellerCurItem('eorder_set');
  220. return View::fetch($this->template_dir . 'eorder_set');
  221. } else {
  222. $store_model = model('store');
  223. $store_model->editStore(array(
  224. 'expresscf_kdn_if_open' => input('post.expresscf_kdn_if_open'),
  225. 'expresscf_kdn_id' => input('post.expresscf_kdn_id'),
  226. 'expresscf_kdn_key' => input('post.expresscf_kdn_key'),
  227. 'expresscf_kdn_printer' => input('post.expresscf_kdn_printer'),
  228. ), array('store_id' => session('store_id')));
  229. ds_json_encode(10000, lang('ds_common_save_succ'));
  230. }
  231. }
  232. /**
  233. * 电子面单
  234. */
  235. public function eorder_list()
  236. {
  237. $expresscf_kdn_config_model = model('expresscf_kdn_config');
  238. $condition = array();
  239. $condition[] = array('store_id', '=', session('store_id'));
  240. $expresscf_kdn_config_list = $expresscf_kdn_config_model->getExpresscfKdnConfigList($condition, '*', 10);
  241. foreach ($expresscf_kdn_config_list as $key => $val) {
  242. $condition = array();
  243. $condition[] = array('express_code', '=', $val['express_code']);
  244. $expresscf_kdn_config_list[$key]['express_name'] = Db::name('express')->where($condition)->value('express_name');
  245. $expresscf_kdn_config_list[$key]['expresscf_kdn_config_pay_type_text'] = lang('expresscf_kdn_config_pay_type')[$val['expresscf_kdn_config_pay_type']];
  246. }
  247. View::assign('expresscf_kdn_config_list', $expresscf_kdn_config_list);
  248. View::assign('show_page', $expresscf_kdn_config_model->page_info->render());
  249. /* 设置卖家当前菜单 */
  250. $this->setSellerCurMenu('sellerdeliverset');
  251. /* 设置卖家当前栏目 */
  252. $this->setSellerCurItem('eorder_list');
  253. return View::fetch($this->template_dir . 'eorder_list');
  254. }
  255. /**
  256. * 电子面单
  257. */
  258. public function eorder_add()
  259. {
  260. if (!request()->isPost()) {
  261. $express_list = rkcache('express', true);
  262. //快递公司
  263. $my_express_list = ds_getvalue_byname('storeextend', 'store_id', session('store_id'), 'express');
  264. if (!empty($my_express_list)) {
  265. $my_express_list = explode(',', $my_express_list);
  266. foreach ($express_list as $k => $v) {
  267. if (!in_array($v['express_id'], $my_express_list))
  268. unset($express_list[$k]);
  269. }
  270. } else {
  271. $express_list = array();
  272. }
  273. View::assign('my_express_list', array_values($express_list));
  274. /* 设置卖家当前菜单 */
  275. $this->setSellerCurMenu('sellerdeliverset');
  276. /* 设置卖家当前栏目 */
  277. $this->setSellerCurItem('eorder_add');
  278. return View::fetch($this->template_dir . 'eorder_form');
  279. } else {
  280. $express_code = input('post.express_code');
  281. $data = array(
  282. 'store_id' => session('store_id'),
  283. 'express_code' => $express_code,
  284. 'expresscf_kdn_config_customer_name' => input('post.expresscf_kdn_config_customer_name'),
  285. 'expresscf_kdn_config_customer_pwd' => input('post.expresscf_kdn_config_customer_pwd'),
  286. 'expresscf_kdn_config_send_site' => input('post.expresscf_kdn_config_send_site'),
  287. 'expresscf_kdn_config_send_staff' => input('post.expresscf_kdn_config_send_staff'),
  288. 'expresscf_kdn_config_month_code' => input('post.expresscf_kdn_config_month_code'),
  289. 'expresscf_kdn_config_pay_type' => input('post.expresscf_kdn_config_pay_type'),
  290. );
  291. $expresscf_kdn_config_validate = ds_validate('expresscf_kdn_config');
  292. if (!$expresscf_kdn_config_validate->scene('expresscf_kdn_config_add')->check($data)) {
  293. ds_json_encode(10000, $expresscf_kdn_config_validate->getError());
  294. }
  295. $expresscf_kdn_config_model = model('expresscf_kdn_config');
  296. $condition = array();
  297. $condition[] = array('store_id', '=', session('store_id'));
  298. $condition[] = array('express_code', '=', $express_code);
  299. $expresscf_kdn_config_info = $expresscf_kdn_config_model->getExpresscfKdnConfigInfo($condition);
  300. if ($expresscf_kdn_config_info) {
  301. ds_json_encode(10000, '电子面单已存在');
  302. }
  303. $flag = $expresscf_kdn_config_model->addExpresscfKdnConfig($data);
  304. if (!$flag) {
  305. ds_json_encode(10000, lang('ds_common_op_fail'));
  306. }
  307. ds_json_encode(10000, lang('ds_common_save_succ'));
  308. }
  309. }
  310. /**
  311. * 电子面单
  312. */
  313. public function eorder_edit()
  314. {
  315. $expresscf_kdn_config_id = input('get.expresscf_kdn_config_id');
  316. $expresscf_kdn_config_model = model('expresscf_kdn_config');
  317. $condition = array();
  318. $condition[] = array('store_id', '=', session('store_id'));
  319. $condition[] = array('expresscf_kdn_config_id', '=', $expresscf_kdn_config_id);
  320. $expresscf_kdn_config_info = $expresscf_kdn_config_model->getExpresscfKdnConfigInfo($condition);
  321. if (!request()->isPost()) {
  322. View::assign('expresscf_kdn_config_info', $expresscf_kdn_config_info);
  323. $express_list = rkcache('express', true);
  324. //快递公司
  325. $my_express_list = ds_getvalue_byname('storeextend', 'store_id', session('store_id'), 'express');
  326. if (!empty($my_express_list)) {
  327. $my_express_list = explode(',', $my_express_list);
  328. foreach ($express_list as $k => $v) {
  329. if (!in_array($v['express_id'], $my_express_list))
  330. unset($express_list[$k]);
  331. }
  332. } else {
  333. $express_list = array();
  334. }
  335. View::assign('my_express_list', array_values($express_list));
  336. /* 设置卖家当前菜单 */
  337. $this->setSellerCurMenu('sellerdeliverset');
  338. /* 设置卖家当前栏目 */
  339. $this->setSellerCurItem('eorder_edit');
  340. return View::fetch($this->template_dir . 'eorder_form');
  341. } else {
  342. if (!$expresscf_kdn_config_info) {
  343. ds_json_encode(10000, '电子面单不存在');
  344. }
  345. $data = array(
  346. 'expresscf_kdn_config_customer_name' => input('post.expresscf_kdn_config_customer_name'),
  347. 'expresscf_kdn_config_customer_pwd' => input('post.expresscf_kdn_config_customer_pwd'),
  348. 'expresscf_kdn_config_send_site' => input('post.expresscf_kdn_config_send_site'),
  349. 'expresscf_kdn_config_send_staff' => input('post.expresscf_kdn_config_send_staff'),
  350. 'expresscf_kdn_config_month_code' => input('post.expresscf_kdn_config_month_code'),
  351. 'expresscf_kdn_config_pay_type' => input('post.expresscf_kdn_config_pay_type'),
  352. );
  353. $expresscf_kdn_config_validate = ds_validate('expresscf_kdn_config');
  354. if (!$expresscf_kdn_config_validate->scene('expresscf_kdn_config_edit')->check($data)) {
  355. ds_json_encode(10000, $expresscf_kdn_config_validate->getError());
  356. }
  357. $flag = $expresscf_kdn_config_model->editExpresscfKdnConfig($data, $condition);
  358. if (!$flag) {
  359. ds_json_encode(10000, lang('ds_common_op_fail'));
  360. }
  361. ds_json_encode(10000, lang('ds_common_save_succ'));
  362. }
  363. }
  364. /**
  365. * 电子面单
  366. */
  367. public function eorder_del()
  368. {
  369. $expresscf_kdn_config_id = intval(input('param.expresscf_kdn_config_id'));
  370. if ($expresscf_kdn_config_id <= 0) {
  371. ds_json_encode(10001, lang('param_error'));
  372. }
  373. $expresscf_kdn_config_model = model('expresscf_kdn_config');
  374. $condition = array();
  375. $condition[] = array('expresscf_kdn_config_id', '=', $expresscf_kdn_config_id);
  376. $condition[] = array('store_id', '=', session('store_id'));
  377. $delete = $expresscf_kdn_config_model->delExpresscfKdnConfig($condition);
  378. if ($delete) {
  379. ds_json_encode(10000, lang('ds_common_op_succ'));
  380. } else {
  381. ds_json_encode(10001, lang('ds_common_op_fail'));
  382. }
  383. }
  384. /**
  385. * 默认配送区域设置
  386. */
  387. public function deliver_region()
  388. {
  389. if (!request()->isPost()) {
  390. $deliver_region = array(
  391. '', ''
  392. );
  393. if (strpos($this->store_info['deliver_region'], '|')) {
  394. $deliver_region = explode('|', $this->store_info['deliver_region']);
  395. }
  396. View::assign('deliver_region', $deliver_region);
  397. /* 设置卖家当前菜单 */
  398. $this->setSellerCurMenu('sellerdeliverset');
  399. /* 设置卖家当前栏目 */
  400. $this->setSellerCurItem('deliver_region');
  401. return View::fetch($this->template_dir . 'deliver_region');
  402. } else {
  403. model('store')->editStore(array('deliver_region' => input('post.area_ids') . '|' . input('post.region')), array('store_id' => session('store_id')));
  404. ds_json_encode(10000, lang('ds_common_save_succ'));
  405. }
  406. }
  407. /**
  408. * 发货单打印设置
  409. */
  410. public function print_set()
  411. {
  412. $store_info = $this->store_info;
  413. if (!request()->isPost()) {
  414. View::assign('store_info', $store_info);
  415. /* 设置卖家当前菜单 */
  416. $this->setSellerCurMenu('sellerdeliverset');
  417. /* 设置卖家当前栏目 */
  418. $this->setSellerCurItem('print_set');
  419. return View::fetch($this->template_dir . 'print_set');
  420. } else {
  421. $data = array(
  422. 'store_printexplain' => input('store_printexplain')
  423. );
  424. $sellerdeliverset_validate = ds_validate('sellerdeliverset');
  425. if (!$sellerdeliverset_validate->scene('print_set')->check($data)) {
  426. $this->error($sellerdeliverset_validate->getError());
  427. }
  428. $update_arr = array();
  429. //上传认证文件
  430. if ($_FILES['store_seal']['name'] != '') {
  431. $file_name = session('store_id') . '_' . date('YmdHis') . rand(10000, 99999) . '.png';
  432. $res = ds_upload_pic(ATTACH_STORE, 'store_seal');
  433. if ($res['code']) {
  434. $file_name = $res['data']['file_name'];
  435. $update_arr['store_seal'] = $file_name;
  436. //删除旧认证图片
  437. if (!empty($store_info['store_seal'])) {
  438. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_STORE . DIRECTORY_SEPARATOR . $store_info['store_seal']);
  439. }
  440. } else {
  441. $this->error($res['msg']);
  442. }
  443. }
  444. $update_arr['store_printexplain'] = input('post.store_printexplain');
  445. $rs = model('store')->editStore($update_arr, array('store_id' => session('store_id')));
  446. if ($rs) {
  447. $this->success(lang('ds_common_save_succ'));
  448. } else {
  449. $this->error(lang('ds_common_save_fail'));
  450. }
  451. }
  452. }
  453. /**
  454. * 用户中心右边,小导航
  455. *
  456. * @param string $menu_type 导航类型
  457. * @param string $menu_key 当前导航的menu_key
  458. * @return
  459. */
  460. function getSellerItemList()
  461. {
  462. $menu_array = array(
  463. array(
  464. 'name' => 'daddress',
  465. 'text' => lang('store_deliver_daddress_list'),
  466. 'url' => (string) url('Sellerdeliverset/index')
  467. ),
  468. array(
  469. 'name' => 'express',
  470. 'text' => lang('store_deliver_default_express'),
  471. 'url' => (string) url('Sellerdeliverset/express')
  472. ),
  473. array(
  474. 'name' => 'eorder_set',
  475. 'text' => lang('eorder_set'),
  476. 'url' => (string) url('Sellerdeliverset/eorder_set')
  477. ),
  478. array(
  479. 'name' => 'eorder_list',
  480. 'text' => lang('eorder_list'),
  481. 'url' => (string) url('Sellerdeliverset/eorder_list')
  482. ),
  483. array(
  484. 'name' => 'free_freight',
  485. 'text' => lang('free_freight'),
  486. 'url' => (string) url('Sellerdeliverset/free_freight')
  487. ),
  488. array(
  489. 'name' => 'deliver_region',
  490. 'text' => lang('default_delivery_area'),
  491. 'url' => (string) url('Sellerdeliverset/deliver_region')
  492. ),
  493. array(
  494. 'name' => 'print_set',
  495. 'text' => lang('print_set'),
  496. 'url' => (string) url('Sellerdeliverset/print_set')
  497. )
  498. );
  499. return $menu_array;
  500. }
  501. }