Sellerdeliverset.php 22 KB

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