| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?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 "qimall_addons_store_clerk".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $store_id 门店id
- * @property int $user_id 会员id
- * @property int $goods_id o2o商品id
- * @property int $nums 累计核销订单数
- * @property float $total_money 累计核销金额
- * @property string $remark 备注
- * @property int $status 状态[0禁用 1启用 -1删除]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- */
- class StoreClerk extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_store_clerk}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'store_id', 'user_id', 'goods_id', 'nums', 'status', 'created_at', 'updated_at'], 'integer'],
- [['total_money'], 'number'],
- [['remark'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'store_id' => '门店id',
- 'user_id' => '会员id',
- 'goods_id' => 'o2o商品id',
- 'nums' => '累计核销订单数',
- 'total_money' => '累计核销金额',
- 'remark' => '备注',
- 'status' => '状态[0禁用 1启用 -1删除]',
- 'created_at' => '创建时间',
- 'updated_at' => '修改时间',
- ];
- }
- public function getUser(){
- return $this->hasOne(User::class, ['id' => 'user_id']);
- }
- /**
- * @desc:保存数据
- * @Author: hua
- * @Date: 2021/10/23
- * @Time: 18:07
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return StoreClerk|false|null
- */
- public static function setData(array $params)
- {
- try {
- if (!empty($params['mall_id']) && !empty($params['store_id']) && !empty($params['user_id'])) {
- $model = self::findOne(['mall_id' => $params['mall_id'], 'store_id' => $params['store_id'], 'user_id' => $params['user_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- }
- } else {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- public static function updateData(array $params)
- {
- try {
- if (!empty($params['id'])) {
- $model = self::findOne(['mall_id' => $params['mall_id'], 'store_id' => $params['store_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($model)) throw new \Exception('服务不存在或已删除');
- if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- }
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * 维护已核销的订单数和已核销的总金额
- *
- * @param int $id
- * @param int $nums
- * @param float $totalMoney
- *
- * @return void
- */
- public static function incrNumsAndTotalMoney(int $id, int $nums, float $totalMoney)
- {
- self::updateAllCounters(['nums' => $nums, 'total_money' => $totalMoney], ['id' => $id]);
- }
- }
|