| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- namespace common\models\goods;
- use common\enums\StatusEnum;
- use Exception;
- use Yii;
- use yii\helpers\Json;
- /**
- * This is the model class for table "{{%free_shipping_rules}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $mch_id 商户ID
- * @property string $name 规则名称
- * @property string $rule 规则详
- * @property int $status 状态【1启用 0禁用 -1删除】
- * @property int $created_at 创建时间
- * @property int $updated_at 更新时间
- * @property int $select_com 选择地区组件[0=多选地区,1=单选地区]
- */
- class FreeShippingRules extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%free_shipping_rules}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'mch_id', 'status' ,'select_com' ,'created_at', 'updated_at', 'rule_type', 'num'], 'integer'],
- [['money'], 'number'],
- [['rule'], 'required'],
- [['rule'], 'string'],
- [['name'], 'string', 'max' => 65],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'mch_id' => '商户ID',
- 'name' => '规则名称',
- 'money' => '包邮订单金额',
- 'rule' => '规则详情',
- 'status' => '状态【1启用 0禁用 -1删除】',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- 'select_com' => '选择地区组件[0=多选地区,1=单选地区]',
- ];
- }
- /**
- * 保存数据
- * @Author bing
- * @DateTime 2021-08-26 14:16:24
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @param array $params
- * @return object|boolean
- */
- public static function setData(array $params){
- try{
- if(!empty($params['id'])){
- $model = self::findOne(['and',['id' => $params['id'],'mall_id' => $params['mall_id']],['<>','status',StatusEnum::DELETE]]);
- if(empty($model)) throw new \Exception('规则存在或已删除');
- }else{
- $model = new self();
- $model->loadDefaultValues();
- }
- //isset($params['rule']) && $params['rule'] = json_encode($params['rule'],JSON_UNESCAPED_UNICODE);
- if(!$model->load($params,'') || !$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * 获取运费模板列表
- * @Author bing
- * @DateTime 2021-08-26 13:00:11
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @param array $cond
- * @param array $with
- * @param integer $is_array
- * @return array|null
- */
- public static function getFreeShippingRules(array $cond=[],array $with=[],bool $is_array=true,string $select='*'){
- $default_cond = [['<>','status',StatusEnum::DELETE]];
- $cond = array_merge($default_cond,$cond);
- $query = self::find()->select($select);
- self::paramPack(['where'=>$cond,'with'=>$with],$query);
- $cates = $query->asArray($is_array)->all();
- return $cates;
- }
- /**
- * 获取包邮规则的包邮地区id
- * @Author: lun
- * @DateTime: 2021/9/29 0029 9:26
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $mall_id
- * @return array
- */
- public static function getFreeShippingRulesArea($mall_id, $mch_id)
- {
- $list = self::getFreeShippingRules([['mall_id' => $mall_id, 'mch_id' => $mch_id]]);
- if (empty($list)) return [];
- $districtArr = [];
- foreach ($list as $item) {
- $districtArr[] = [
- 'money' => $item['money'],
- 'district_ids' => array_column(Json::decode($item['rule'], true), 'id'),
- 'rule_type' => $item['rule_type'],
- 'num' => $item['num'],
- ];
- }
- return $districtArr;
- }
- }
|