id; $saasUser = SaasUser::findOne($id); $user = null; $store = Store::findOne($saasUser->store_id); if ($store) { $user = User::findOne(['store_id' => $store->id, 'binding' => $saasUser->mobile, 'is_delete' => 1]); } $parentSaasUser = SaasUser::findOne($saasUser->parent_id); $data = [ 'mobile' => $saasUser->mobile, 'name' => $saasUser->name, 'avatar' => $saasUser->avatar, 'league_price' => $saasUser->league_price, 'store_name' => $store->name ?: '', 'store_user_name' => $user ? $user->nickname : '', 'parent_name' => $parentSaasUser->name ?: '总店', 'parent_id' => $parentSaasUser->id ?: 0, 'created_at' => date('Y-m-d H:i:s', $saasUser->created_at) ]; return [ 'code' => 0, 'msg' => 'success', 'data' => $data ]; } //用户联盟券 public function userLeague() { $user_name = $this->user_name; $mobile = $this->mobile; $query = SaasUser::find()->where(['is_delete' => 0]); if (!empty($user_name)) { $query->andWhere(['LIKE', 'name', $user_name]); } if (!empty($mobile)) { $query->andWhere(['LIKE', 'mobile', $mobile]); } $query->select('id, name, mobile, avatar, league_price')->orderBy('league_price desc, id desc'); $pagination = pagination_make($query); $pagination['total_user_league'] = SaasUser::find()->where(['is_delete' => 0])->sum('league_price') ?: 0; return [ 'code' => 0, 'msg' => '', 'data' => $pagination ]; } //商家联盟券 public function storeLeague() { $store_name = $this->store_name; $store_category_id = $this->store_category_id; $query = Store::find()->where(['is_delete' => 0]); if (!empty($store_name)) { $query->andWhere(['LIKE', 'name', $store_name]); } if (!empty($store_category_id)) { $query->andWhere(['category_id' => $store_category_id]); } $query->select('id, name, category_id, logo, league_price')->orderBy('league_price desc, id desc'); $pagination = pagination_make($query); foreach ($pagination['list'] as &$item) { $item['category_name'] = SaasCategory::findOne($item['category_id'])->name ?: ''; if (empty($item['logo'])) { $item['logo'] = Option::get('logo', $item['id'], 'store')['value']; if (empty($item['logo'])) { $item['logo'] = Option::get('web_log', $item['id'], 'web')['value']; } } } $pagination['total_user_league'] = SaasUser::find()->where(['is_delete' => 0])->sum('league_price') ?: 0; return [ 'code' => 0, 'msg' => '', 'data' => $pagination ]; } //商家联盟券记录 public function storeLeagueLog() { $id = $this->id; $store_name = $this->store_name; $store_category_id = $this->store_category_id; $start_time = $this->start_time; $end_time = $this->end_time; // $query = SaaSLeaguePriceLog::find()->alias('lpl')->where(['lpl.role' => SaaSLeaguePriceLog::ROLE_STORE, 'lpl.is_delete' => 0]); $query->leftJoin(['s' => Store::tableName()], 's.id = lpl.store_id'); if ($id) { $query->andWhere(['lpl.store_id' => $id]); } if ($store_name) { $query->andWhere(['LIKE', 's.name', $store_name]); } if ($store_category_id) { $query->andWhere(['s.category_id' => $store_category_id]); } if ($start_time) { $start_time = strtotime($start_time); $query->andWhere(['>=', 'lpl.addtime', $start_time]); } if ($end_time) { $end_time = strtotime($end_time); $query->andWhere(['<=', 'lpl.addtime', $end_time]); } $query->andWhere(['>', 'lpl.league_price', 0]); $query->select('lpl.id, lpl.type, lpl.order_id, lpl.send_or_take_type, lpl.saas_user_id, lpl.after, lpl.before, lpl.league_price, lpl.addtime, s.name, s.category_id, s.logo, s.id store_id') ->orderBy('lpl.id desc'); $pagination = pagination_make($query); foreach ($pagination['list'] as &$item) { $item['addtime'] = date("Y-m-d H:i:s", $item['addtime']); $item['send_or_take_type'] = (int)$item['send_or_take_type']; $item['category_name'] = SaasCategory::findOne($item['category_id'])->name ?: ''; $item['type'] = (int)$item['type']; $item['type_name'] = SaaSLeaguePriceLog::getTypeStr($item['type']); if (empty($item['logo'])) { $item['logo'] = Option::get('logo', $item['store_id'], 'store')['value']; if (empty($item['logo'])) { $item['logo'] = Option::get('web_log', $item['store_id'], 'web')['value']; } } $item['order_no'] = ''; if ($item['order_id']) { if (in_array($item['type'], [ SaaSLeaguePriceLog::TYPE_ORDER_REBATE,//下单返利 SaaSLeaguePriceLog::TYPE_CANCEL,//订单取消退回 SaaSLeaguePriceLog::TYPE_DEDUCTION,//下单抵扣 ])) { $order = Order::findOne($item['order_id']); } if ($item['type'] === SaaSLeaguePriceLog::TYPE_LEAGUE_RECHARGE) {//联盟券 $order = RechargeReOrder::findOne($item['order_id']); } if (in_array($item['type'], [ SaaSLeaguePriceLog::TYPE_WITHDRAW, SaaSLeaguePriceLog::TYPE_WITHDRAW_REJECT, ])) {//联盟券提现 $order = Cash::findOne($item['order_id']); } if ($item['type'] === SaaSLeaguePriceLog::TYPE_FACE_PAY_ORDER) {//当面付 $order = \app\plugins\scanCodePay\models\Order::findOne($item['order_id']); } if (isset($order)) { $item['order_no'] = $order->order_no ?: ''; } } $item['user_name'] = SaasUser::findOne($item['saas_user_id'])->name ?: ''; } $league_price_query = Store::find()->where(['is_delete' => 0]); if ($id) { $league_price_query->andWhere(['id' => $id]); } $league_price = $league_price_query->select('league_price')->sum('league_price') ?: 0; return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $pagination['list'], 'pageNo' => $pagination['pageNo'], 'totalCount' => $pagination['totalCount'], 'league_price' => $league_price ], ]; } public function storeLeagueInfo() { $id = $this->id; $store = Store::findOne($id); $store_district = District::find()->where(['id' => [$store->district_id, $store->city_id, $store->province_id]])->select('name')->column(); $data = [ 'store_name' => $store->name, 'category_name' => SaasCategory::findOne($store->category_id)->name ?: '', 'address' => implode('', $store_district) . $store->address, 'logo' => $store->logo ?: (Option::get('logo', $store->id, 'store')['value'] ?: Option::get('web_log', $store->id, 'web')['value']), 'league_price' => $store->league_price ]; return [ 'code' => 0, 'msg' => 'success', 'data' => $data ]; } }