| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace common\models\goods;
- use common\enums\StatusEnum;
- use common\enums\WhetherEnum;
- use Exception;
- use Yii;
- /**
- * This is the model class for table "{{%goods_service}}".
- *
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $mch_id 商户ID
- * @property string $name 服务名称
- * @property string $remark 备注、描述
- * @property int $sort 排序
- * @property int $is_default 是否为默认服务【1是 0否】
- * @property int $status 状态【1启用 0禁用 -1删除】
- * @property int $created_at 创建时间
- * @property int $updated_at 更新时间
- */
- class GoodsService extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%goods_service}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'mch_id', 'sort', 'created_at', 'updated_at'], 'integer'],
- ['is_default', 'in', 'range' => [WhetherEnum::ENABLED,WhetherEnum::DISABLED]],
- ['status', 'in', 'range' => [StatusEnum::ENABLED,StatusEnum::DISABLED,StatusEnum::DELETE]],
- [['name'], 'string', 'max' => 65],
- [['remark'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'mch_id' => '商户ID',
- 'name' => '服务名称',
- 'remark' => '备注、描述',
- 'sort' => '排序',
- 'is_default' => '是否为默认服务【1是 0否】',
- 'status' => '状态【1启用 0禁用 -1删除】',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- /**
- * 保存数据
- * @Author bing
- * @DateTime 2021-08-24 15:34:48
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @param array $params
- * @return void
- */
- public static function setData(array $params){
- try{
- if(!empty($params['id'])){
- $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'],'status'=>[StatusEnum::ENABLED,StatusEnum::DISABLED]]);
- if(empty($model)) throw new Exception('服务不存在或已删除');
- }else{
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $params['mall_id'];
- $model->mch_id = $params['mch_id'];
- }
- 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 getServices(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;
- }
- }
|