Sellerdeliverset.php 23 KB

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