ExpressController.class.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Seller\Controller;
  10. use Seller\Model\ExpressModel;
  11. class ExpressController extends CommonController{
  12. protected function _initialize(){
  13. parent::_initialize();
  14. $this->breadcrumb1='发货设置';
  15. $this->breadcrumb2='快递管理';
  16. }
  17. public function index(){
  18. $model=new ExpressModel();
  19. $search = array();
  20. $search['store_id'] = array('in','0,'.SELLERUID);
  21. $data=$model->show_express_page($search);
  22. $seller_express_relat = M('seller_express_relat')->where( array('store_id' => SELLERUID) )->select();
  23. $express_ids = array();
  24. foreach($seller_express_relat as $express)
  25. {
  26. $express_ids[] = $express['express_id'];
  27. }
  28. foreach($data['list'] as $key => $val)
  29. {
  30. $val['is_selected'] = 0;
  31. if(!empty($express_ids) && in_array($val['id'], $express_ids))
  32. {
  33. $val['is_selected'] = 1;
  34. }
  35. $data['list'][$key] = $val;
  36. }
  37. $this->assign('seller_id',SELLERUID);
  38. $this->assign('empty',$data['empty']);// 赋值数据集
  39. $this->assign('list',$data['list']);// 赋值数据集
  40. $this->assign('page',$data['page']);// 赋值分页输出
  41. $this->display();
  42. }
  43. function toggle_express_show()
  44. {
  45. $eid = intval(I('post.eid'));
  46. $rel_ex = M('seller_express_relat')->where( array('store_id' => SELLERUID, 'express_id' => $eid) )->find();
  47. if(empty($rel_ex))
  48. {
  49. $data = array();
  50. $data['express_id'] = $eid;
  51. $data['store_id'] = SELLERUID;
  52. M('seller_express_relat')->add($data);
  53. } else {
  54. M('seller_express_relat')->where( array('store_id' => SELLERUID, 'express_id' => $eid) )->delete();
  55. }
  56. echo json_encode( array('code' => 1) );
  57. die();
  58. }
  59. function add(){
  60. if(IS_POST){
  61. $data=I('post.');
  62. $data['store_id'] = SELLERUID;
  63. $data['addtime'] = time();
  64. if( empty($data['express_name']) )
  65. {
  66. $return = array(
  67. 'status'=>'fail',
  68. 'message'=>'请填写快递名称',
  69. 'jump'=>U('Express/index')
  70. );
  71. }else{
  72. $res = M('seller_express')->add($data);
  73. if($res) {
  74. $return = array(
  75. 'status'=>'success',
  76. 'message'=>'新增成功',
  77. 'jump'=>U('Express/index')
  78. );
  79. } else {
  80. $return = array(
  81. 'status'=>'fail',
  82. 'message'=>'新增失败',
  83. 'jump'=>U('Express/index')
  84. );
  85. }
  86. }
  87. $this->osc_alert($return);
  88. }
  89. $this->crumbs='新增';
  90. $this->action=U('Express/add');
  91. $this->display('edit');
  92. }
  93. function edit(){
  94. if(IS_POST){
  95. $data=I('post.');
  96. $data['addtime'] = time();
  97. $ck_info = M('seller_express')->where(array('id' =>$data['id'],'store_id' =>SELLERUID))->find();
  98. if(empty($ck_info)) {
  99. $return = array(
  100. 'status'=>'fail',
  101. 'message'=>'非法操作',
  102. 'jump'=>U('Express/index')
  103. );
  104. $this->osc_alert($return);
  105. }
  106. $res = M('seller_express')->save($data);
  107. if($res) {
  108. $return = array(
  109. 'status'=>'success',
  110. 'message'=>'编辑成功',
  111. 'jump'=>U('Express/index')
  112. );
  113. } else {
  114. $return = array(
  115. 'status'=>'fail',
  116. 'message'=>'编辑失败',
  117. 'jump'=>U('Express/index')
  118. );
  119. }
  120. $this->osc_alert($return);
  121. }
  122. $this->crumbs='编辑';
  123. $this->action=U('Express/edit');
  124. $this->d=M('seller_express')->find(I('id'));
  125. $this->display('edit');
  126. }
  127. public function del(){
  128. $id = I('get.id', 0);
  129. $res = M('seller_express')->where( array('id' => $id) )->delete();
  130. if($res) {
  131. $return = array(
  132. 'status'=>'success',
  133. 'message'=>'删除成功',
  134. 'jump'=>U('Express/index')
  135. );
  136. } else {
  137. $return = array(
  138. 'status'=>'fail',
  139. 'message'=>'删除失败',
  140. 'jump'=>U('Express/index')
  141. );
  142. }
  143. $this->osc_alert($return);
  144. }
  145. public function config()
  146. {
  147. $_GPC = I('request.');
  148. $this->gpc = $_GPC;
  149. $condition = '';
  150. $pindex = max(1, intval($_GPC['page']));
  151. $psize = 20;
  152. if (!empty($_GPC['keyword'])) {
  153. $condition .= ' and name like "%'.$_GPC['keyword'].'%" ';
  154. }
  155. $label = M()->query('SELECT id,name,simplecode,customer_name,customer_pwd FROM ' . C('DB_PREFIX') . "lionfish_comshop_express
  156. WHERE 1 " . $condition . ' order by id desc limit ' . (($pindex - 1) * $psize) . ',' . $psize);
  157. $total = M('lionfish_comshop_express')->where('1 ' . $condition)->count();
  158. $pager = pagination2($total, $pindex, $psize);
  159. $this->label = $label;
  160. $this->total = $total;
  161. $this->pager = $pager;
  162. $this->display();
  163. }
  164. public function addexpress()
  165. {
  166. $_GPC = I('request.');
  167. if (IS_POST) {
  168. $data = $_GPC['data'];
  169. D('Seller/Express')->update($data);
  170. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  171. }
  172. $this->display();
  173. }
  174. public function editexpress()
  175. {
  176. $_GPC = I('request.');
  177. $id = intval($_GPC['id']);
  178. if (!empty($id)) {
  179. $item = M('lionfish_comshop_express')->field('id,name,simplecode,customer_name,customer_pwd')->where( array('id' => $id) )->find();
  180. $this->item = $item;
  181. }
  182. if (IS_POST) {
  183. $data = $_GPC['data'];
  184. D('Seller/Express')->update($data);
  185. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  186. }
  187. $this->display('Express/addexpress');
  188. }
  189. public function delexpress()
  190. {
  191. $_GPC = I('request.');
  192. $id = intval($_GPC['id']);
  193. if (empty($id)) {
  194. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  195. }
  196. $items = M('lionfish_comshop_express')->field('id,name')->where('id in( ' . $id . ' ) ')->select();
  197. if (empty($item)) {
  198. $item = array();
  199. }
  200. foreach ($items as $item) {
  201. M('lionfish_comshop_express')->where( array('id' => $item['id']) )->delete();
  202. }
  203. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  204. }
  205. public function localtownconfig()
  206. {
  207. $_GPC = I('request.');
  208. //供应商
  209. $supper_info = get_agent_logininfo();
  210. if (IS_POST) {
  211. $data = ((is_array($_GPC['parameter']) ? $_GPC['parameter'] : array()));
  212. $localtown_confirm_delivery_distance = $data['localtown_confirm_delivery_distance'];
  213. if(!is_numeric($localtown_confirm_delivery_distance) || $localtown_confirm_delivery_distance < 10){
  214. $ret = '确认送达距离必须为数字,且大于10米';
  215. show_json(0, $ret);
  216. }
  217. $localtown_grabbing_distance = $data['localtown_grabbing_distance'];
  218. if(!is_numeric($localtown_grabbing_distance) || $localtown_grabbing_distance < 10){
  219. $ret = '配送员抢单距离必须为数字,且大于10米';
  220. show_json(0, $ret);
  221. }
  222. $localtown_expected_delivery_status = $data['localtown_expected_delivery_status'];
  223. $localtown_delivery_space_time = $data['localtown_delivery_space_time'];
  224. if($localtown_expected_delivery_status == 1){
  225. if(empty($localtown_delivery_space_time) || floor($localtown_delivery_space_time)!=$localtown_delivery_space_time || $localtown_delivery_space_time < 15){
  226. $ret = '配送时间段间隔必须为整数,且不小于15';
  227. show_json(0, $ret);
  228. }
  229. }
  230. $localtown_business_hours_status = $data['localtown_business_hours_status'];
  231. if($localtown_business_hours_status == 1){
  232. $localtown_business_hours_begin = $data['localtown_business_hours_begin'];
  233. $localtown_business_hours_end = $data['localtown_business_hours_end'];
  234. if(empty($localtown_business_hours_begin) || empty($localtown_business_hours_end)){
  235. $ret = '营业时间段不能为空';
  236. show_json(0, $ret);
  237. }
  238. $hours_end_time = strtotime($localtown_business_hours_end);
  239. $hours_end_begin = strtotime($localtown_business_hours_begin);
  240. if($hours_end_time < $hours_end_begin){//结束时间小于开始时间
  241. $xc_time = $hours_end_time+24*60*60-$hours_end_begin;
  242. if($xc_time < 60*60){
  243. $ret = '营业时间段不能小于1个小时';
  244. show_json(0, $ret);
  245. }
  246. }else{
  247. $xc_time = $hours_end_time-$hours_end_begin;
  248. if($xc_time < 60*60){
  249. $ret = '营业时间段不能小于1个小时';
  250. show_json(0, $ret);
  251. }
  252. }
  253. }
  254. if(!empty($supper_info['id'])){
  255. D('Seller/SupplyConfig')->update($data);
  256. }else{
  257. D('Seller/Config')->update($data);
  258. }
  259. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  260. }
  261. if(!empty($supper_info['id'])){
  262. $data = D('Seller/SupplyConfig')->get_all_config();
  263. $this->is_supply = 1;
  264. }else{
  265. $data = D('Seller/Config')->get_all_config();
  266. $this->is_supply = 0;
  267. }
  268. if( isset($data['localtown_shop_province_id']) && $data['localtown_shop_province_id'] != '' )
  269. {
  270. $data['province_name'] =$data['localtown_shop_province_id'];
  271. $data['city_name'] = $data['localtown_shop_city_id'];
  272. $data['area_name'] = $data['localtown_shop_area_id'];
  273. $data['country_name'] = $data['localtown_shop_country_id'];
  274. }
  275. $this->data = $data;
  276. if(empty($supper_info['id'])){
  277. $this->display('Express/localtownconfig');
  278. }else{
  279. $this->display('Express/supply_localtownconfig');
  280. }
  281. }
  282. public function deconfig()
  283. {
  284. $_GPC = I('request.');
  285. if (IS_POST) {
  286. $data = ((is_array($_GPC['parameter']) ? $_GPC['parameter'] : array()));
  287. if($data['delivery_type_ziti'] == 2 && $data['delivery_type_tuanz'] == 2 && $data['delivery_type_express'] == 2){
  288. show_json(0, '请选择开启一项配送服务!');
  289. }
  290. $data['delivery_type_ziti'] = trim($data['delivery_type_ziti']);
  291. $data['delivery_type_express'] = $data['delivery_type_express'];
  292. $data['delivery_type_tuanz'] = $data['delivery_type_tuanz'];
  293. $data['delivery_tuanz_money'] = $data['delivery_tuanz_money'];
  294. $data['delivery_express_name'] = $data['delivery_express_name'];
  295. $data['delivery_diy_sort'] = $data['delivery_diy_sort'];
  296. $data['shopcar_tab_all_name'] = $data['shopcar_tab_all_name'];
  297. $data['shopcar_tab_express_name'] = $data['shopcar_tab_express_name'];
  298. $data['order_lou_meng_hao'] = $data['order_lou_meng_hao'];
  299. $data['order_lou_meng_hao_placeholder'] = $data['order_lou_meng_hao_placeholder'];
  300. D('Seller/Config')->update($data);
  301. if(empty($data['delivery_diy_sort']) || !isset($data['delivery_diy_sort']))
  302. $data['delivery_diy_sort'] = '0,1,2';
  303. $data['delivery_diy_sort_arr'] = explode(",", $data['delivery_diy_sort']);
  304. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  305. }
  306. $data = D('Seller/Config')->get_all_config();
  307. if(empty($data['delivery_diy_sort']) || !isset($data['delivery_diy_sort'])) $data['delivery_diy_sort'] = '0,1,2';
  308. $data['delivery_diy_sort_arr'] = explode(",", $data['delivery_diy_sort']);
  309. $this->data = $data;
  310. $this->display();
  311. }
  312. public function config2()
  313. {
  314. $open_info = M('config')->where( array('name' => 'EXPRESS_OPEN') )->find();
  315. $ebuss_info = M('config')->where( array('name' => 'EXPRESS_EBUSS_ID') )->find();
  316. $exappkey = M('config')->where( array('name' => 'EXPRESS_APPKEY') )->find();
  317. $is_open = $open_info['value'];
  318. $ebuss_id = $ebuss_info['value'];
  319. $express_appkey = $exappkey['value'];
  320. $this->is_open = $is_open;
  321. $this->ebuss_id = $ebuss_id;
  322. $this->express_appkey = $express_appkey;
  323. $this->type = 1;
  324. $this->display();
  325. }
  326. function configadd()
  327. {
  328. $data = I('post.');
  329. /**
  330. array(4) { ["is_open"]=> string(1) "1" ["ebuss_id"]=> string(7) "1276098" ["express_appkey"]=> string(36) "9933541f-2d17-4312-8250-a9cecdbe633d" ["send"]=> string(6) "提交" }
  331. **/
  332. M('config')->where( array('name' => 'EXPRESS_OPEN') )->save( array('value' => $data['is_open']) );
  333. M('config')->where( array('name' => 'EXPRESS_EBUSS_ID') )->save( array('value' => $data['ebuss_id']) );
  334. M('config')->where( array('name' => 'EXPRESS_APPKEY') )->save( array('value' => $data['express_appkey']) );
  335. $return = array(
  336. 'status'=>'success',
  337. 'message'=>'保存成功',
  338. 'jump'=>U('Express/config')
  339. );
  340. $this->osc_alert($return);
  341. }
  342. /**
  343. * @author cy 2020-08-04
  344. * 达达配送平台配置
  345. */
  346. public function localtown_imdada_config(){
  347. $_GPC = I('request.');
  348. if (IS_POST) {
  349. $data = ((is_array($_GPC['parameter']) ? $_GPC['parameter'] : array()));
  350. //达达第三方配送开启状态
  351. $data['is_localtown_imdada_status'] = trim($data['is_localtown_imdada_status']);
  352. //商户编号
  353. $data['localtown_imdada_merchant_id'] = $data['localtown_imdada_merchant_id'];
  354. //APPKEY
  355. $data['localtown_imdada_appkey'] = $data['localtown_imdada_appkey'];
  356. //AppSecret
  357. $data['localtown_imdada_appsecret'] = $data['localtown_imdada_appsecret'];
  358. D('Seller/Config')->update($data);
  359. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  360. }
  361. $data = D('Seller/Config')->get_all_config();
  362. $this->data = $data;
  363. $this->display();
  364. }
  365. /**
  366. * @author cy 2020-08-04
  367. * 顺丰同城配置
  368. */
  369. public function localtown_sf_config(){
  370. $_GPC = I('request.');
  371. if (IS_POST) {
  372. $data = ((is_array($_GPC['parameter']) ? $_GPC['parameter'] : array()));
  373. //顺丰同城开启状态
  374. $data['is_localtown_sf_status'] = trim($data['is_localtown_sf_status']);
  375. //开发者ID
  376. $data['localtown_sf_dev_id'] = $data['localtown_sf_dev_id'];
  377. //密钥
  378. $data['localtown_sf_dev_key'] = $data['localtown_sf_dev_key'];
  379. //顺丰店铺ID
  380. $data['localtown_sf_store_id'] = $data['localtown_sf_store_id'];
  381. D('Seller/Config')->update($data);
  382. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  383. }
  384. $data = D('Seller/Config')->get_all_config();
  385. $this->data = $data;
  386. $this->display();
  387. }
  388. /**
  389. * @author yj 2021-01-14
  390. * 码科同城配置
  391. */
  392. public function localtown_mk_config(){
  393. $_GPC = I('request.');
  394. //IA_ROOT . '/addons/lionfish_comshop/
  395. //$addons_check_filepath = IA_ROOT."/addons/lionfish_comshop_plugin_make/module.php";
  396. //$addons_check_filepath = ROOT_PATH."/addons/lionfish_comshop_plugin_make/module.php";
  397. //$is_exist_plu = file_exists( $addons_check_filepath );
  398. $is_exist_plu =1;
  399. $this->is_exist_plu = $is_exist_plu;
  400. if (IS_POST) {
  401. $data = ((is_array($_GPC['parameter']) ? $_GPC['parameter'] : array()));
  402. //码科同城开启状态
  403. $data['is_localtown_mk_status'] = trim($data['is_localtown_mk_status']);
  404. //码科
  405. $data['localtown_mk_token'] = $data['localtown_mk_token'];
  406. $last_code = substr( $data['localtown_mk_url'] , -1 ,1);
  407. if( $last_code != '/' )
  408. {
  409. $data['localtown_mk_url'] = $data['localtown_mk_url'].'/';
  410. }
  411. D('Seller/Config')->update($data);
  412. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  413. }
  414. $data = D('Seller/Config')->get_all_config();
  415. $this->data = $data;
  416. $this->display();
  417. }
  418. /**
  419. * @author cy 2021-02-02
  420. * @desc 蜂鸟即配配置
  421. */
  422. public function localtown_ele_config(){
  423. $_GPC = I('request.');
  424. if (IS_POST) {
  425. $data = ((is_array($_GPC['parameter']) ? $_GPC['parameter'] : array()));
  426. //蜂鸟即配开启状态
  427. $data['is_localtown_ele_status'] = $data['is_localtown_ele_status'];
  428. //商户APPID
  429. $data['localtown_ele_app_id'] = trim($data['localtown_ele_app_id']);
  430. //商户SecretKey
  431. $data['localtown_ele_secret_key'] = trim($data['localtown_ele_secret_key']);
  432. //门店编号
  433. $data['localtown_ele_store_code'] = trim($data['localtown_ele_store_code']);
  434. //门店名称
  435. $data['localtown_ele_transport_name'] = trim($data['localtown_ele_transport_name']);
  436. //取货点地址
  437. $data['localtown_ele_transport_address'] = trim($data['localtown_ele_transport_address']);
  438. //取货点经度
  439. $data['localtown_ele_transport_longitude'] = trim($data['localtown_ele_transport_longitude']);
  440. //取货点纬度
  441. $data['localtown_ele_transport_latitude'] = trim($data['localtown_ele_transport_latitude']);
  442. //取货点联系方式
  443. $data['localtown_ele_transport_tel'] = trim($data['localtown_ele_transport_tel']);
  444. //取货点经纬度来源
  445. $data['localtown_ele_position_source'] = trim($data['localtown_ele_position_source']);
  446. //取货点备注
  447. $data['localtown_ele_transport_remark'] = trim($data['localtown_ele_transport_remark']);
  448. if($data['is_localtown_ele_status'] == 1){
  449. if(empty($data['localtown_ele_app_id'])){
  450. show_json(0, '请正确填写商户APPID');
  451. }
  452. if(empty($data['localtown_ele_secret_key'])){
  453. show_json(0, '请正确填写商户SecretKey');
  454. }
  455. if(empty($data['localtown_ele_store_code'])){
  456. show_json(0, '请正确填写门店编号');
  457. }
  458. if(!ctype_alnum($data['localtown_ele_store_code'])){
  459. show_json(0, '门店编号必须是数字、字母的组合');
  460. }
  461. if(empty($data['localtown_ele_transport_name'])){
  462. show_json(0, '请正确填写门店名称');
  463. }
  464. if(empty($data['localtown_ele_transport_address'])){
  465. show_json(0, '请正确填写取货点地址');
  466. }
  467. if(empty($data['localtown_ele_transport_longitude'])){
  468. show_json(0, '请正确填写取货点经度');
  469. }
  470. if(empty($data['localtown_ele_transport_latitude'])){
  471. show_json(0, '请正确填写取货点纬度');
  472. }
  473. if(empty($data['localtown_ele_transport_tel'])){
  474. show_json(0, '请正确填写取货点联系方式');
  475. }
  476. }
  477. D('Seller/Config')->update($data);
  478. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  479. }
  480. $data = D('Seller/Config')->get_all_config();
  481. $this->data = $data;
  482. $this->display();
  483. }
  484. /**
  485. * @author cy 2021-02-24
  486. * @desc 订单推送配置
  487. */
  488. public function ordersendconfig(){
  489. $_GPC = I('request.');
  490. if (IS_POST) {
  491. $data = ((is_array($_GPC['parameter']) ? $_GPC['parameter'] : array()));
  492. //是否开启订单推送
  493. $data['is_order_push_status'] = $data['is_order_push_status'];
  494. //第三方配送公司
  495. $data['order_push_third_distribution_company'] = trim($data['order_push_third_distribution_company']);
  496. if($data['is_order_push_status'] == 1){
  497. if(empty($data['order_push_third_distribution_company'])){
  498. show_json(0, '请选择第三方配送公司');
  499. }
  500. }
  501. D('Seller/Config')->update($data);
  502. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  503. }else{
  504. $data = D('Seller/Config')->get_all_config();
  505. $this->third_delivery_company_list = $this->getThirdDeliveryCompayList($data);
  506. $this->data = $data;
  507. $this->display();
  508. }
  509. }
  510. public function getThirdDeliveryCompayList($config_data){
  511. $company_list = [];
  512. if(isset($config_data['is_localtown_imdada_status']) && $config_data['is_localtown_imdada_status'] == 1){
  513. $company_list[] = ['id'=>'imdada','name'=>'达达配送'];
  514. }
  515. if(isset($config_data['is_localtown_sf_status']) && $config_data['is_localtown_sf_status'] == 1){
  516. $company_list[] = ['id'=>'sf','name'=>'顺丰同城'];
  517. }
  518. if(isset($config_data['is_localtown_mk_status']) && $config_data['is_localtown_mk_status'] == 1){
  519. $company_list[] = ['id'=>'make','name'=>'码科跑腿'];
  520. }
  521. if(isset($config_data['is_localtown_ele_status']) && $config_data['is_localtown_ele_status'] == 1){
  522. $company_list[] = ['id'=>'ele','name'=>'蜂鸟即配'];
  523. }
  524. return $company_list;
  525. }
  526. }
  527. ?>