commit | author | age
|
19351a
|
1 |
<?php |
B |
2 |
|
|
3 |
/** |
|
4 |
* 管理中心 配送方式用到的公共方法 |
|
5 |
|
|
6 |
* |
|
7 |
*/ |
|
8 |
|
|
9 |
if (!defined('IN_ECS')) |
|
10 |
{ |
|
11 |
die('Hacking attempt'); |
|
12 |
} |
|
13 |
|
|
14 |
/* |
|
15 |
* 设置成默认配送方式所涉及到的操作 |
|
16 |
* |
|
17 |
* @param int $sid 配送方式id |
|
18 |
* |
|
19 |
* @return Bool |
|
20 |
*/ |
|
21 |
function set_default_show($sid,$supplier_id=0) |
|
22 |
{ |
|
23 |
global $db,$ecs; |
|
24 |
|
|
25 |
//修改所有已经安装的配送方式为非默认 |
|
26 |
$db->query("update ".$ecs->table('shipping')." set is_default_show = 0 where supplier_id=".$supplier_id." and enabled=1 and shipping_code not in('pups','tc_express')"); |
|
27 |
|
|
28 |
//修改当前配送地址为默认 |
|
29 |
$db->query("update ".$ecs->table('shipping')." set is_default_show = 1 where shipping_id=".$sid." and supplier_id=".$supplier_id); |
|
30 |
|
|
31 |
//删除非默认配送方式下的数据 |
|
32 |
$ret_del = del_no_default($supplier_id); |
|
33 |
|
|
34 |
|
|
35 |
//非默认配送方式下数据与默认配送方式的数据做同步 |
|
36 |
$tb = tongbu_default($sid,$supplier_id); |
|
37 |
|
|
38 |
|
|
39 |
return true; |
|
40 |
} |
|
41 |
|
|
42 |
//获取当前平台下所有已经安装的非默认,非同城快递,非门店自提配送地址 |
|
43 |
function get_all_install_shipping($supplier_id=0){ |
|
44 |
global $db,$ecs; |
|
45 |
|
|
46 |
return $db->getCol("select shipping_id from ".$ecs->table('shipping')." where supplier_id=".$supplier_id." and is_default_show=0 and enabled=1 and shipping_code not in('pups','tc_express')"); |
|
47 |
} |
|
48 |
|
|
49 |
//删除非默认配送方式下对应表ecs_shipping_area和ecs_ecs_area_region下的数据 |
|
50 |
function del_no_default($supplier_id=0){ |
|
51 |
global $db,$ecs; |
|
52 |
$shipping_ids = get_all_install_shipping($supplier_id); |
|
53 |
|
|
54 |
if(count($shipping_ids)>0){ |
|
55 |
$shipping_area_ids = $db->getCol("select shipping_area_id from ".$ecs->table("shipping_area")." where shipping_id in(".implode(',',$shipping_ids).")"); |
|
56 |
|
|
57 |
if(empty($shipping_area_ids)){ |
|
58 |
return true; |
|
59 |
} |
|
60 |
|
|
61 |
$db->query("delete from ".$ecs->table("area_region")." where shipping_area_id in(".implode(',',$shipping_area_ids).")"); |
|
62 |
|
|
63 |
$db->query("delete from ".$ecs->table("shipping_area")." where shipping_area_id in(".implode(',',$shipping_area_ids).")"); |
|
64 |
} |
|
65 |
return true; |
|
66 |
} |
|
67 |
|
|
68 |
//用设置的配送方式的数据同步非默认配送方式下的数据 |
|
69 |
function tongbu_default($shpping_id,$supplier_id=0){ |
|
70 |
global $db,$ecs; |
|
71 |
|
|
72 |
$shipping_area_ids = $db->getCol("select shipping_area_id from ".$ecs->table("shipping_area")." where shipping_id=".$shpping_id); |
|
73 |
$area_region_info = array(); |
|
74 |
if(count($shipping_area_ids)>0){ |
|
75 |
$not_default_shipping_ids = get_all_install_shipping($supplier_id); |
|
76 |
|
|
77 |
foreach($shipping_area_ids as $key=>$val){ |
|
78 |
foreach($not_default_shipping_ids as $k=>$v){ |
|
79 |
$db->query("insert into ".$ecs->table('shipping_area')."(shipping_area_name,shipping_id,configure) select shipping_area_name,".$v.",configure from ".$ecs->table('shipping_area')." where shipping_area_id=".$val); |
|
80 |
$area_region_info[$val][]=$db->insert_id(); |
|
81 |
} |
|
82 |
} |
|
83 |
} |
|
84 |
if(count($area_region_info)>0){ |
|
85 |
foreach($area_region_info as $key=>$val){ |
|
86 |
foreach($val as $k=>$v){ |
|
87 |
$db->query("insert into ".$ecs->table('area_region')."(shipping_area_id,region_id) select ".$v.",region_id from ".$ecs->table('area_region')." where shipping_area_id=".$key); |
|
88 |
} |
|
89 |
} |
|
90 |
} |
|
91 |
return true; |
|
92 |
|
|
93 |
} |
|
94 |
?> |