| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace addons\Store\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use common\models\user\User;
- use Yii;
- /**
- * This is the model class for table "addons_store_clerk_income".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $store_id 门店id
- * @property int $total_amount 核销总金额
- * @property int $total_count 核销次数
- * @property string $total_income 核销收入
- * @property string $status 状态[0禁用 1启用 -1删除]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- */
- class StoreClerkIncomeData extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_store_clerk_income_data}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'store_id', 'total_count','created_at', 'updated_at','status'], 'integer'],
- [['total_amount','total_income'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'store_id' => '门店id',
- 'total_amount' => '总金额',
- 'total_income' => '总收益',
- 'total_count' => '总次数',
- 'status'=>'状态',
- 'created_at' => '创建时间',
- 'updated_at' => '修改时间',
- ];
- }
- public function getStore()
- {
- return $this->hasOne(Store::class, ['id' => 'store_id']);
- }
- public static function setData(array $params)
- {
- $t = Yii::$app->db->beginTransaction();
- 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();
- }
-
- if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- $t->commit();
- return $model;
- } catch (\Exception $e) {
- $t->rollBack();
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|