commit | author | age
|
90c639
|
1 |
<?php |
Z |
2 |
|
|
3 |
namespace app\models; |
|
4 |
|
|
5 |
use app\forms\common\version\Compatible; |
|
6 |
use app\forms\permission\role\AdminRole; |
|
7 |
use app\forms\permission\role\BaseRole; |
|
8 |
use app\forms\permission\role\SuperAdminRole; |
|
9 |
use Yii; |
|
10 |
|
|
11 |
/** |
|
12 |
* This is the model class for table "{{%mall}}". |
|
13 |
* |
|
14 |
* @property string $id |
|
15 |
* @property string $created_at |
|
16 |
* @property string $updated_at |
|
17 |
* @property string $deleted_at |
|
18 |
* @property string $expired_at |
|
19 |
* @property string $name |
|
20 |
* @property string $user_id |
|
21 |
* @property int $is_recycle |
|
22 |
* @property int $is_disable |
|
23 |
* @property int $is_delete |
|
24 |
* @property User $user |
|
25 |
* @property MallSetting[] $option |
|
26 |
* @property BaseRole $role |
|
27 |
*/ |
|
28 |
class Mall extends ModelActiveRecord |
|
29 |
{ |
|
30 |
public $options; |
|
31 |
private $mallAllOptions; |
|
32 |
private $role; |
|
33 |
|
|
34 |
/** |
|
35 |
* {@inheritdoc} |
|
36 |
*/ |
|
37 |
public static function tableName() |
|
38 |
{ |
|
39 |
return '{{%mall}}'; |
|
40 |
} |
|
41 |
|
|
42 |
/** |
|
43 |
* {@inheritdoc} |
|
44 |
*/ |
|
45 |
public function rules() |
|
46 |
{ |
|
47 |
return [ |
|
48 |
[['created_at', 'updated_at', 'deleted_at', 'expired_at'], 'safe'], |
|
49 |
[['user_id', 'is_recycle', 'is_delete', 'is_disable'], 'integer'], |
|
50 |
[['name'], 'string', 'max' => 64], |
|
51 |
]; |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* {@inheritdoc} |
|
56 |
*/ |
|
57 |
public function attributeLabels() |
|
58 |
{ |
|
59 |
return [ |
|
60 |
'id' => 'ID', |
|
61 |
'created_at' => 'Created At', |
|
62 |
'updated_at' => 'Updated At', |
|
63 |
'deleted_at' => 'Deleted At', |
|
64 |
'expired_at' => 'Expired At', |
|
65 |
'name' => '商城名称', |
|
66 |
'user_id' => '用户 ID', |
|
67 |
'is_recycle' => '商城回收状态', |
|
68 |
'is_disable' => '商城禁用状态', |
|
69 |
'is_delete' => 'Is Delete', |
|
70 |
]; |
|
71 |
} |
|
72 |
|
|
73 |
public function getUser() |
|
74 |
{ |
|
75 |
return $this->hasOne(User::className(), ['id' => 'user_id']); |
|
76 |
} |
|
77 |
|
|
78 |
public function getOption() |
|
79 |
{ |
|
80 |
return $this->hasMany(MallSetting::className(), ['mall_id' => 'id']); |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* 获取商城单个配置 |
|
85 |
* @param $column |
|
86 |
* @return mixed|null |
|
87 |
* @throws \Exception |
|
88 |
*/ |
|
89 |
public function getMallSettingOne($column) |
|
90 |
{ |
|
91 |
$settings = $this->getMallSetting([$column]); |
|
92 |
if (isset($settings[$column])) { |
|
93 |
return $settings[$column]; |
|
94 |
} |
|
95 |
return null; |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* 获取商城多个配置 |
|
100 |
* @param array $columns |
|
101 |
* @return array|null|\yii\db\ActiveRecord |
|
102 |
* @throws \Exception |
|
103 |
*/ |
|
104 |
public function getMallSetting($columns = []) |
|
105 |
{ |
|
106 |
if ($this->mallAllOptions) { |
|
107 |
$newOption = $this->mallAllOptions; |
|
108 |
} else { |
|
109 |
$detail = Yii::$app->mall->toArray(); |
|
110 |
$detail['option'] = Yii::$app->mall->option; |
|
111 |
foreach ($detail['option'] as $key => &$value) { |
|
112 |
if ($value->key == 'send_type') { |
|
113 |
$value->value = Compatible::getInstance()->sendType($value->value); |
|
114 |
} |
|
115 |
} |
|
116 |
unset($value); |
|
117 |
|
|
118 |
$defaultList = $this->getDefault(); |
|
119 |
$detailOptions = []; |
|
120 |
foreach ($detail['option'] as $item) { |
|
121 |
$detailOptions[$item['key']] = $item['value']; |
|
122 |
} |
|
123 |
|
|
124 |
// 查找出列表中 没有的默认参数 |
|
125 |
foreach ($defaultList as $dKey => $dItem) { |
|
126 |
if (!isset($detailOptions[$dKey])) { |
|
127 |
$detail['option'][] = [ |
|
128 |
'key' => $dKey, |
|
129 |
'value' => $dItem, |
|
130 |
]; |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
$newOption = []; |
|
135 |
// 需要被转成数字类型的 |
|
136 |
$arr = [ |
|
137 |
'add_app_bg_transparency', 'add_app_bg_radius', 'is_show_cart', 'is_show_goods_name', 'is_show_stock', |
|
138 |
'is_sales', 'is_must_login', 'is_goods_video', 'is_open', 'open_type', 'is_auto_open', |
|
139 |
'show_contact_type', 'is_video_number', 'is_video_number_member', 'is_remind_sell_time' |
|
140 |
]; |
|
141 |
// 需要被json_decode的 |
|
142 |
$jsonArr = [ |
|
143 |
'good_negotiable', 'payment_type', 'send_type', 'business_time_type_week', 'business_time_type_day', |
|
144 |
'quick_customize_new_params', 'send_type_desc', 'week_list', 'time_list', 'video_number_member_list', |
|
145 |
'video_number_template_list', 'customer_service_list', 'custom_theme_color' |
|
146 |
]; |
|
147 |
foreach ($detail['option'] as $k => $item) { |
|
148 |
if (in_array($item['key'], $arr)) { |
|
149 |
$item['value'] = (int)$item['value']; |
|
150 |
} |
|
151 |
if (in_array($item['key'], $jsonArr)) { |
|
152 |
$value = is_array($item['value']) ? $item['value'] : json_decode($item['value'], true); |
|
153 |
$newOption[$item['key']] = $value; |
|
154 |
} else { |
|
155 |
if ($item['key'] == 'web_service_url') { |
|
156 |
$newOption[$item['key']] = urldecode($item['value']); |
|
157 |
} elseif ($item['key'] == 'quick_customize_params') { |
|
158 |
$newOption[$item['key']] = ''; |
|
159 |
} else { |
|
160 |
$newOption[$item['key']] = $item['value']; |
|
161 |
} |
|
162 |
} |
|
163 |
} |
|
164 |
|
|
165 |
// 添加商城配置默认值 |
|
166 |
$defaultArr = $this->getDefault(); |
|
167 |
foreach ($defaultArr as $k => $item) { |
|
168 |
if (!isset($newOption[$k])) { |
|
169 |
$newOption[$k] = $item; |
|
170 |
} |
|
171 |
} |
|
172 |
|
|
173 |
$this->mallAllOptions = $newOption; |
|
174 |
} |
|
175 |
|
|
176 |
// 返回指定字段配置 |
|
177 |
if ($columns) { |
|
178 |
$newData = []; |
|
179 |
foreach ($columns as $column) { |
|
180 |
if (!isset($newOption[$column])) { |
|
181 |
throw new \Exception('字段' . $column . '不存在'); |
|
182 |
} |
|
183 |
$newData[$column] = $newOption[$column]; |
|
184 |
} |
|
185 |
|
|
186 |
return $newData; |
|
187 |
} |
|
188 |
|
|
189 |
$detail['setting'] = $newOption; |
|
190 |
return $detail; |
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* TODO 商城配置默认值 |
|
195 |
* @return array |
|
196 |
*/ |
|
197 |
public function getDefault() |
|
198 |
{ |
|
199 |
$host = PHP_SAPI != 'cli' ? \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . "/" : ''; |
|
200 |
return [ |
|
201 |
'share_title' => '', //分享标题 |
|
202 |
'share_pic' => '', //分享图片 |
|
203 |
'contact_tel' => '', // 联系电话 |
|
204 |
'over_time' => 10, // 未支付订单超时时间(分钟) |
|
205 |
'delivery_time' => 15, // 收货时间(天) |
|
206 |
'after_sale_time' => 0, // 售后时间(天) |
|
207 |
/** |
|
208 |
* 支付方式 |
|
209 |
* online_pay 线上支付 |
|
210 |
* balance 余额支付 |
|
211 |
* huodao 货到付款 |
|
212 |
*/ |
|
213 |
'payment_type' => [ |
|
214 |
'online_pay', |
|
215 |
], |
|
216 |
'send_type' => [ |
|
217 |
'express', 'offline', |
|
218 |
], // 发货方式 express--快递 offline--自提 city--同城 |
|
219 |
'send_type_desc' => [ |
|
220 |
[ |
|
221 |
'key' => 'express', |
|
222 |
'origin' => '快递配送', |
|
223 |
'modify' => '', |
|
224 |
], |
|
225 |
[ |
|
226 |
'key' => 'offline', |
|
227 |
'origin' => '到店自提', |
|
228 |
'modify' => '', |
|
229 |
], |
|
230 |
[ |
|
231 |
'key' => 'city', |
|
232 |
'origin' => '同城配送', |
|
233 |
'modify' => '', |
|
234 |
], |
|
235 |
], |
|
236 |
///////////////////////////////////////////////////////////////////////////////// |
|
237 |
'mall_logo_pic' => $host . 'statics/img/mall/poster-big-shop.png', //商城logo |
|
238 |
'kdniao_mch_id' => '', // 快递鸟商户ID |
|
239 |
'kdniao_api_key' => '', // 快递鸟API KEY |
|
240 |
'express_select_type' => '', //0快递鸟 'wd' 支付宝 |
|
241 |
'express_aliapy_code' => '', //支付宝code |
|
242 |
///////////////////////////////////////////////////////////////////////////////// |
|
243 |
'member_integral' => '0', // 会员积分抵扣比例 |
|
244 |
'member_integral_rule' => '', // 会员积分使用规格 |
|
245 |
/** |
|
246 |
* 商品面议联系方式 |
|
247 |
* contact 客服 |
|
248 |
* contact_tel 联系电话 |
|
249 |
* contact_web 外链客服 |
|
250 |
*/ |
|
251 |
'good_negotiable' => [ |
|
252 |
'contact', |
|
253 |
], |
|
254 |
'mobile_verify' => '1', // 商城手机号是否验证 0.关闭 1.开启 |
|
255 |
'is_small_app' => '0', //跳转小程序开关 |
|
256 |
'small_app_id' => '', // 跳转小程序APP ID |
|
257 |
'small_app_url' => '', // 跳转小程序APP URL |
|
258 |
'small_app_pic' => $host . 'statics/img/mall/small_app_pic.png', // 跳转小程序APP 图标 |
|
259 |
'is_customer_services' => '0', // 是否开启在线客服 0.关闭 1.开启 |
|
260 |
'customer_services_pic' => $host . 'statics/img/mall/customer_services_pic.png', // 在线客服图标 |
|
261 |
'is_dial' => '0', // 是否开启一键拨号 0.关闭 1.开启 |
|
262 |
'dial_pic' => $host . 'statics/img/mall/dial_pic.png', // 一键拨号图标 |
|
263 |
'is_web_service' => '0', // 客服外链开关 |
|
264 |
'web_service_url' => '', // 客服外链 |
|
265 |
'web_service_pic' => $host . 'statics/img/mall/web_service_pic.png', // 客服外链图标 |
|
266 |
|
|
267 |
'is_quick_customize' => '0', //自定义按钮开关 |
|
268 |
'quick_customize_pic' => '', //图片路径 |
|
269 |
'quick_customize_open_type' => '', //跳转方式 |
|
270 |
//'quick_customize_params' => '', //跳转参数 (数据庞大 无用途) |
|
271 |
'quick_customize_new_params' => '', //跳转参数 |
|
272 |
'quick_customize_link_url' => '', //跳转参数 |
|
273 |
|
|
274 |
'is_show_stock' => '1', // 是否显示售罄图标 |
|
275 |
'is_use_stock' => '1', //是否使用默认的售罄图标 |
|
276 |
'sell_out_pic' => '', //售罄图标 |
|
277 |
'sell_out_other_pic' => '', //4:3售罄图片 |
|
278 |
/** |
|
279 |
* 快捷导航样式 |
|
280 |
* 1.样式1(点击收起) |
|
281 |
* 2.样式2(全部展示) |
|
282 |
*/ |
|
283 |
'is_quick_navigation' => '0', |
|
284 |
'quick_navigation_style' => '1', |
|
285 |
'quick_navigation_opened_pic' => $host . 'statics/img/mall/quick_navigation_opened_pic.png', // 快捷导航展开图标 |
|
286 |
'quick_navigation_closed_pic' => $host . 'statics/img/mall/quick_navigation_closed_pic.png', // 快捷导航收起图标 |
|
287 |
/** |
|
288 |
* 分类样式 |
|
289 |
* 1.大图模式(不显示侧栏) |
|
290 |
* 2.大图模式(显示侧栏) |
|
291 |
* 3.小图模式(不显示侧栏) |
|
292 |
* 4.小图模式(显示侧栏) |
|
293 |
* 5.商品列表模式 |
|
294 |
*/ |
|
295 |
'is_common_user_member_price' => '1', // 普通用户会员价显示开关 0.关闭 1.开启 |
|
296 |
'is_member_user_member_price' => '1', // 会员用户会员价显示开关 0.关闭 1.开启 |
|
297 |
'is_share_price' => '1', // 分销价显示开关 0.关闭 1.开启 |
|
298 |
'is_purchase_frame' => '1', // 首页购买记录框 0.关闭 1.开启 |
|
299 |
'purchase_num' => '0', //轮播订单数 |
|
300 |
'is_comment' => '1', // 商城评价开关 0.关闭 1.开启 |
|
301 |
'is_sales' => '1', // 商城商品销量开关 0.关闭 1.开启 |
|
302 |
// 'is_recommend' => '1',// TODO 即将废弃 推荐商品状态 0.关闭 1.开启 |
|
303 |
'is_mobile_auth' => '0', // 首页授权手机号 0.关闭 1.开启 |
|
304 |
'is_official_account' => '0', // 关联公众号组件 0.关闭 1.开启 |
|
305 |
'is_manual_mobile_auth' => '1', // 手动授权手机号 0.关闭 1.开启 |
|
306 |
'is_icon_members_grade' => '0', //会员等级标识 0关闭 1.开启 |
|
307 |
'is_quick_map' => '0', // 一键导航是否开启 0.关闭 1.开启 |
|
308 |
'quick_map_pic' => $host . 'statics/img/mall/quick_map_pic.png', // 一键导航图标 |
|
309 |
'quick_map_address' => '', // 商家地址 |
|
310 |
'latitude' => '', //纬度 |
|
311 |
'longitude' => '', // 经度 |
|
312 |
'is_quick_home' => '0', //返回首页开关 |
|
313 |
'quick_home_pic' => $host . 'statics/img/mall/quick_home_pic.png', // 返回首页图标 |
|
314 |
// 'nav_row_num' => '4',// TODO 废弃 导航图标每行显示个数 |
|
315 |
'is_icon_super_vip' => '1', // 超级会员卡显示开关 0.关闭 1.开启 |
|
316 |
'is_show_normal_vip' => '1', // 普通用户超级会员卡显示开关 0.关闭 1.开启 |
|
317 |
'is_show_super_vip' => '1', // 会员用户超级会员卡显示开关 0.关闭 1.开启 |
|
318 |
'is_show_cart' => '1', // 购物车显示开关 |
|
319 |
'is_show_sales_num' => '1', //已售量(商品列表) 0.关闭 1.开启 |
|
320 |
'is_show_goods_name' => '1', //商品名称 |
|
321 |
'is_underline_price' => '1', //划线价 |
|
322 |
'is_list_underline_price' => '1', //列表划线价 |
|
323 |
'is_express' => '1', //快递 |
|
324 |
'is_not_share_show' => '1', //非分销商分销中心显示 |
|
325 |
'is_show_cart_fly' => '0', //购物车悬浮按钮 |
|
326 |
'is_show_score_top' => '0', //回到顶部悬浮按钮 |
|
327 |
'is_goods_video' => '1', // 商品视频特色展示开关 |
|
328 |
|
|
329 |
'logo' => '', //手机端商城管理店铺设置页面,logo可自定义图片上传 |
|
330 |
// 添加到我的小程序 |
|
331 |
'is_add_app' => '0', |
|
332 |
'add_app_bg_color' => '#000000', |
|
333 |
'add_app_bg_transparency' => 100, |
|
334 |
'add_app_bg_radius' => 36, |
|
335 |
'add_app_text' => '添加到我的小程序,购买更便捷', |
|
336 |
'add_app_text_color' => '#ffffff', |
|
337 |
'add_app_icon_color_type' => '1', |
|
338 |
'theme_color' => 'a', // 商城风格 |
|
339 |
'is_required_position' => 0, // 定位地址是否必填 |
|
340 |
'is_share_tip' => 0, // 下单申请分销上提醒开关 |
|
341 |
'is_must_login' => 0, // 强制授权开关 |
|
342 |
|
|
343 |
'is_show_hot_goods' => 1, //是否显示热搜开关 |
|
344 |
|
|
345 |
'kd100_key' => '', //快递100 |
|
346 |
'kd100_customer' => '',//快递100 |
|
347 |
'kd100_secret' => '',//快递100 |
|
348 |
'kd100_siid' => '', //快递100 |
|
349 |
'kd100_yum' => '1', //快递100云打印 |
|
350 |
'print_type' => '', //那个电子面单 |
|
351 |
|
|
352 |
'is_open' => 1, //是否开业 1、营业 2、打烊 |
|
353 |
'open_type' => 1, //营业时间段 1、全天 2、自定义 |
|
354 |
'week_list' => [],// 1.星期一 2.星期二 ... |
|
355 |
'time_list' => [], // [['07:00', '12:00'],['13:00', '17:00']] |
|
356 |
'is_auto_open' => 1, // 设置是否自动开业 1、不设置 2、自定义 |
|
357 |
'auto_open_time' => '', // 设置自动开业时间 |
|
358 |
'show_contact_type' => 0, // 显示客服类型 0--不显示 1--显示在线客服 2--显示客服外链 |
|
359 |
|
|
360 |
'is_video_number' => 0, |
|
361 |
'video_number_app_id' => '', |
|
362 |
'video_number_app_secret' => '', |
|
363 |
'video_number_share_title' => '', |
|
364 |
'is_video_number_member' => 0, |
|
365 |
'video_number_member_list' => [], |
|
366 |
'video_number_template_list' => [], |
|
367 |
'video_number_user_1' => '', |
|
368 |
'video_number_user_2' => '', |
|
369 |
|
|
370 |
'kdniao_select_type' => 'free', |
|
371 |
'customer_service_list' => [],// 客服微信列表 最多10个 |
|
372 |
'show_goods_auth' => '-1', |
|
373 |
'buy_goods_auth' => '-1', |
|
374 |
//默认好评功能 |
|
375 |
'has_order_evaluate' => 0, |
|
376 |
'order_evaluate_day' => 0, |
|
377 |
|
|
378 |
'is_remind_sell_time' => 0, |
|
379 |
'custom_theme_color' => [ |
|
380 |
'main' => '#ff4544', |
|
381 |
'main_text' => '#ffffff', |
|
382 |
'secondary' => '#f39800', |
|
383 |
'secondary_text' => '#ffffff' |
|
384 |
], // 自定义主题色 |
|
385 |
]; |
|
386 |
} |
|
387 |
|
|
388 |
/** |
|
389 |
* @return AdminRole|BaseRole|SuperAdminRole |
|
390 |
* @throws \Exception |
|
391 |
* 获取商城所属账户的权限 |
|
392 |
*/ |
|
393 |
public function getRole() |
|
394 |
{ |
|
395 |
if (!$this->role) { |
|
396 |
$user = \Yii::$app->mall->user; |
|
397 |
$userIdentity = $user->identity; |
|
398 |
$config = [ |
|
399 |
'userIdentity' => $user->identity, |
|
400 |
'user' => $user, |
|
401 |
'mall' => \Yii::$app->mall |
|
402 |
]; |
|
403 |
if ($userIdentity->is_super_admin == 1) { |
|
404 |
// 总管理员 |
|
405 |
$this->role = new SuperAdminRole($config); |
|
406 |
} elseif ($userIdentity->is_admin == 1) { |
|
407 |
// 子管理员 |
|
408 |
$this->role = new AdminRole($config); |
|
409 |
} else { |
|
410 |
throw new \Exception('未知用户权限'); |
|
411 |
} |
|
412 |
} |
|
413 |
return $this->role; |
|
414 |
} |
|
415 |
} |