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]); } }