AddonsXhsGoodsVisit.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace addons\Xhs\common\models;
  3. use Yii;
  4. use yii\db\Exception;
  5. /**
  6. * This is the model class for table "qimall_addons_xhs_goods_visit".
  7. *
  8. * @property int $id ID
  9. * @property int $mall_id 商城ID
  10. * @property int $user_id 用户ID
  11. * @property int $content_id 内容 id
  12. * @property int $goods_id 商品 id
  13. * @property int $created_at 创建时间
  14. * @property int $updated_at 更新时间
  15. */
  16. class AddonsXhsGoodsVisit extends \common\models\base\BaseActiveRecord
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function tableName()
  22. {
  23. return '{{%addons_xhs_goods_visit}}';
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function rules()
  29. {
  30. return [
  31. [['mall_id', 'user_id', 'content_id', 'goods_id'], 'required'],
  32. [['mall_id', 'user_id', 'content_id', 'goods_id', 'created_at', 'updated_at'], 'integer'],
  33. ];
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function attributeLabels()
  39. {
  40. return [
  41. 'id' => 'ID',
  42. 'mall_id' => '商城ID',
  43. 'user_id' => '用户ID',
  44. 'content_id' => '内容 id',
  45. 'goods_id' => '商品 id',
  46. 'created_at' => '创建时间',
  47. 'updated_at' => '更新时间',
  48. ];
  49. }
  50. /**
  51. * 保存数据
  52. * @Author: ltm
  53. * @DateTime: 2021/12/13 0022 17:13
  54. * @Copyright: copyright (c) 2021 广东七件事集团
  55. * @param array $params
  56. * @return AddonsMaterial|bool
  57. */
  58. public static function setData(array $params){
  59. try{
  60. if (!empty($params['id'])) {
  61. $model = self::findOne(['and',['id'=>$params['id'],'mall_id'=>$params['mall_id']]]);
  62. if (empty($model)) throw new Exception('记录不存在或已删除');
  63. }else{
  64. $model = new self();
  65. $model->loadDefaultValues();
  66. $model->mall_id = $params['mall_id'];
  67. }
  68. if(!$model->load($params,'') || !$model->save()){
  69. throw new Exception($model->getErrorMessage());
  70. }
  71. return $model;
  72. }catch(\Exception $e){
  73. self::$static_error = $e->getMessage();
  74. return false;
  75. }
  76. }
  77. }