| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- <?php
- namespace app\modules\admin\models;
- use app\models\Cash;
- use app\models\District;
- use app\models\Option;
- use app\models\Order;
- use app\models\RechargeReOrder;
- use app\models\SaasCategory;
- use app\models\SaaSLeaguePriceLog;
- use app\models\SaasUser;
- use app\models\Store;
- use app\models\User;
- use yii\base\Model;
- class LeagueForm extends Model
- {
- public $id;
- public $store_id;
- public $user_name;
- public $mobile;
- public $store_name;
- public $store_category_id;
-
- public $start_time;
- public $end_time;
- public function rules()
- {
- return [
- [['store_id', 'id', 'store_category_id'], 'integer'],
- [['mobile', 'start_time', 'end_time', 'user_name', 'store_name'], 'string'],
- [['mobile', 'user_name', 'store_name'], 'trim'],
- ];
- }
- //用户联盟券记录
- public function userLeagueInfo()
- {
- $id = $this->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
- ];
- }
- }
|