'ID', 'mall_id' => 'Mall ID', 'user_id' => 'User ID', 'order_id' => 'Order ID', 'superior_user_id' => 'Superior User ID', 'superior_level' => 'Superior Level', 'status' => 'Status', 'created_at' => 'Created At', ]; } /** * @return ActiveQueryInterface the relational query object. */ public function getOrder() { return $this->hasOne(Order::class, ['id' => 'order_id']); } /** * @return ActiveQueryInterface the relational query object. */ public function getUser() { return $this->hasOne(User::class, ['id' => 'user_id']); } /** * 批量添加 * * @param array $data * @return void */ public static function batchInsertData(array $data) { $insert_data = []; foreach ($data as $item) { $insert_data[static::sliceRule($item['superior_user_id'])][] = $item; } foreach ($insert_data as $tb => $items) { static::find() ->createCommand() ->batchInsert(static::getTb($tb), array_keys(reset($items)), $items)->execute(); } } /** * 切割规则 * * @param integer $user_id * @return int */ protected static function sliceRule(int $user_id) { return $user_id % 10 ? $user_id % 10 : 10; } /** * 获取tb * * @param integer $tb * @return string */ protected static function getTb(int $tb) { return '{{%user_team_achievement_order_' . $tb . '}}'; } /** * 删除改站点相关数据 * * @param integer $mall_id * @return void */ public static function deleteMall(int $mall_id) { for ($i = 1; $i <= 10; $i++) { static::$tb = $i; static::deleteAll(['mall_id' => $mall_id]); } } /** * 获取列表 * * @param integer $limit * @param callable|null $callback * @param string $order_by * @return array */ public static function getPaginationListByUid( int $uid, int $limit, callable $callback = null, string $order_by = 'id' ): array { static::$tb = static::sliceRule($uid); return static::getPaginationList($limit, $callback, $order_by); } public static function getTeamAchievementList(int $uid, array $where) { static::$tb = static::sliceRule($uid); return static::find()->where($where); } }