'ID', 'mall_id' => '商城ID', 'store_id' => '门店id', 'user_id' => '用户ID', 'pay_order_num' => '支付订单总数', 'finish_order_num' => '完成订单总数', 'seed_num' => '新增种子金数量', 'collect_seed_num' => '已收取种子金总数量', 'refund_seed_num' => '退款种子金总数量', 'date' => '日期,如20220726', 'status' => '状态,-1:失效,1:正常,2:冻结', 'created_at' => '添加时间戳', 'updated_at' => '更新时间戳', ]; } /** * 创建统计 * @Author: lun * @DateTime: 2022/8/1 0001 16:19 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $mall_id * @param $store_id * @param $user_id * @param $date * @return array|bool */ public static function create($mall_id, $store_id, $user_id, $date) { try { $model = self::find()->where(['mall_id' => $mall_id, 'user_id' => $user_id, 'date' => $date, 'store_id' => $store_id, 'status' => StatusEnum::ENABLED])->one(); if (empty($model)) { $model = new self(); $model->mall_id = $mall_id; $model->store_id = $store_id; $model->user_id = $user_id; $model->date = $date; $model->loadDefaultValues(); } else { $model->updated_at = time(); } if (!$model->save()) throw new Exception($model->getErrorMessage()); return $model->toArray(); } catch (\Exception $e) { self::setStaticError('创建种子金统计:'.$e->getMessage()); return false; } } /** * 保存数据 * @Author: lun * @DateTime: 2022/8/1 0001 16:16 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $params * @param $statistics * @throws \Exception */ public static function setData($params, $statistics = []) { try { $date = date('Ymd', time()); $data = self::create($params['mall_id'], $params['store_id'], $params['user_id'], $date); if ($data === false) throw new \Exception(SeedUserStatistics::getStaticError()); // 修改统计的数据 if ($statistics) { $res = SeedUserStatistics::updateAllCounters($statistics, ['id' => $data['id']]); if ($res === false) throw new \Exception(SeedUserStatistics::getStaticError()); } return true; } catch (\Exception $e) { self::setStaticError($e->getMessage()); return false; } } /** * 修改数据 * @Author: lun * @DateTime: 2022/8/15 0015 10:23 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $mall_id * @param $user_id * @param int $store_id * @param array $params * @throws Exception */ public static function saveStatistics($mall_id, $user_id, $store_id = 0, $params = []) { $update_data['updated_at'] = time(); foreach ($params as $key => $value) { $symbol = $value >= 0 ? '+' : '-'; $update_data[$key] = new Expression($key.$symbol.abs($value)); } $res = self::updateAll($update_data, ['mall_id' => $mall_id, 'store_id' => $store_id, 'user_id' => $user_id, 'status' => StatusEnum::ENABLED]); if (!$res) throw new Exception('修改用户每日统计数据失败'); } }