Sellerdeliverset.php 22 KB

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