BusinessCardMaterialsCate.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace addons\BusinessCard\common\models;
  3. use common\enums\StatusEnum;
  4. use Exception;
  5. use Yii;
  6. /**
  7. * This is the model class for table "qimall_addons_business_card_material_cate".
  8. *
  9. * @property int $id 名片素材分类
  10. * @property int|null $mall_id 商城ID
  11. * @property string|null $name 分类名称
  12. * @property int|null $order_sort 排序
  13. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  14. * @property int|null $created_at 创建时间
  15. * @property int|null $updated_at 更新时间
  16. */
  17. class BusinessCardMaterialsCate extends \common\models\base\BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return 'qimall_addons_business_card_material_cate';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'order_sort', 'status', 'created_at', 'updated_at'], 'integer'],
  33. [['name'], 'string', 'max' => 128],
  34. ];
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'id' => 'ID',
  43. 'mall_id' => 'Mall ID',
  44. 'name' => 'Name',
  45. 'order_sort' => 'Order Sort',
  46. 'status' => 'Status',
  47. 'created_at' => 'Created At',
  48. 'updated_at' => 'Updated At',
  49. ];
  50. }
  51. /**
  52. * 数据设置
  53. */
  54. public static function setData(array $params)
  55. {
  56. try{
  57. if (!isset($params['mall_id']) || empty($params['mall_id'])) throw new Exception('缺少商城ID');
  58. if (isset($params['id']) && !empty($params['id'])) {
  59. $model = self::findOne(['id' => $params['id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  60. if(empty($model)) throw new Exception('素材分类不存在或已删除');
  61. } else {
  62. $model = new self();
  63. $model->loadDefaultValues();
  64. $model->mall_id = $params['mall_id'];
  65. }
  66. if (!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
  67. return $model;
  68. }catch(Exception $e){
  69. self::setStaticError($e->getMessage());
  70. return false;
  71. }
  72. }
  73. }