'ID', 'mall_id' => 'Mall ID', 'user_id' => 'User ID', 'material_id' => 'Material ID', 'share_times' => 'Share Times', 'recent_time' => 'Recent Time', 'status' => 'Status', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } /** * 数据设置 */ public static function setData(array $params) { try{ if (!isset($params['mall_id']) || empty($params['mall_id'])) throw new Exception('缺少商城ID'); if (isset($params['id']) && !empty($params['id'])) { $model = self::findOne([ 'id' => $params['id'], 'mall_id' => $params['mall_id'], 'status' => StatusEnum::ENABLED ]); if(empty($model)) throw new Exception('分享记录不存在或已删除'); } else if (isset($params['user_id']) && !empty($params['user_id']) && isset($params['material_id']) && !empty($params['material_id'])) { $model = self::findOne([ 'user_id' => $params['user_id'], 'material_id' => $params['material_id'], 'mall_id' => $params['mall_id'], 'status' => StatusEnum::ENABLED ]); } if (!empty($model)) { if (isset($params['share_times'])) { $model->share_times = $model->share_times + $params['share_times']; unset($params['share_times']); } } else { $model = new self(); $model->loadDefaultValues(); $model->mall_id = $params['mall_id']; } if (!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage()); return $model; }catch(Exception $e){ self::setStaticError($e->getMessage()); return false; } } }