zm
2021-03-25 d84ff6053b22269a6c59dc005e9efb8de6595988
commit | author | age
90c639 1 <?php
Z 2
3 namespace app\models;
4
5 use Yii;
6 use yii\db\Exception;
7
8 /**
9  * This is the model class for table "{{%share_order_log}}".
10  *
11  * @property int $id
12  * @property int $mall_id
13  * @property string $share_setting 分销设置情况
14  * @property string $order_share_info 订单分销情况
15  * @property string $created_at
16  */
17 class ShareOrderLog extends ModelActiveRecord
18 {
19     /**
20      * {@inheritdoc}
21      */
22     public static function tableName()
23     {
24         return '{{%share_order_log}}';
25     }
26
27     /**
28      * {@inheritdoc}
29      */
30     public function rules()
31     {
32         return [
33             [['mall_id', 'share_setting', 'order_share_info', 'created_at'], 'required'],
34             [['mall_id'], 'integer'],
35             [['share_setting', 'order_share_info'], 'string'],
36             [['created_at'], 'safe'],
37         ];
38     }
39
40     /**
41      * {@inheritdoc}
42      */
43     public function attributeLabels()
44     {
45         return [
46             'id' => 'ID',
47             'mall_id' => 'Mall ID',
48             'share_setting' => '分销设置情况',
49             'order_share_info' => '订单分销情况',
50             'created_at' => 'Created At',
51         ];
52     }
53
54     /**
55      * @param $shareSetting array|string 分销设置情况
56      * @param $orderShareInfo array|string 订单分销情况
57      * @param $mallId integer 商城ID
58      * @return bool
59      * @throws Exception
60      */
61     public static function create($shareSetting, $orderShareInfo, $mallId)
62     {
63         if (!$shareSetting) {
64             throw new Exception('$shareSetting不能为空');
65         }
66
67         if (!$orderShareInfo) {
68             throw new Exception('$shareSetting不能为空');
69         }
70
71         if (is_array($shareSetting)) {
72             $shareSetting = Yii::$app->serializer->encode($shareSetting);
73         }
74
75         if (is_array($orderShareInfo)) {
76             $orderShareInfo = Yii::$app->serializer->encode($orderShareInfo);
77         }
78
79         $model = new self();
80         $model->mall_id = $mallId;
81         $model->share_setting = $shareSetting;
82         $model->order_share_info = $orderShareInfo;
83         $model->created_at = mysql_timestamp();
84         return $model->save();
85     }
86 }