| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers;
- use app\models\Level;
- use app\models\LevelOrder;
- use app\models\Mch;
- use app\models\MchBrands;
- use app\models\MchStaff;
- use app\models\Salesman;
- use app\models\Share;
- use app\models\ShareHolder;
- use app\models\StoreAudit;
- use app\models\User;
- use app\models\SaasUser;
- use app\models\UserGrowthValueLog;
- use app\models\UserShareMoney;
- use app\models\Worker;
- use app\modules\admin\models\AuthRoleForm;
- use app\modules\admin\models\cashier\CashierUserForm;
- use app\modules\admin\models\LevelForm;
- use app\modules\admin\models\SaasStaffForm;
- use app\modules\admin\models\UserForm;
- use app\models\Admin;
- use app\models\StoreCloud;
- use app\models\Store;
- use Yii;
- use app\models\Option;
- use app\constants\OptionSetting;
- use app\models\DeliveryInfo;
- use app\models\LocalDeliveryCourier;
- use app\models\Order;
- use app\models\AccountLog;
- use app\models\UserPayMonth;
- use yii\base\BaseObject;
- use yii\helpers\Json;
- class UserController extends BaseController
- {
- public function actionSaasInfo()
- {
- $md_id = get_md_id();
- $admin = get_admin();
- $mch_id = get_mch_id();
- $adminPermission = AuthRoleForm::getCommonPermission();
- $store_name = '';
- $store = Store::findOne($admin->store_id);
- if ($store) {
- $store_name = $store->name;
- }
- $typename = '商城后台';
- if ($md_id > 0) {
- $typename = '门店后台';
- }
- if ($mch_id > 0) {
- $typename = '入驻商后台';
- }
- $result = [
- 'username' => $admin->username,
- 'name' => $admin->name,
- 'mobile' => $admin->mobile,
- 'email' => $admin->email,
- 'remark' => $admin->remark,
- 'avatar' => $admin->avatar ?: '/avatar2.jpg',
- 'store_id' => $admin->store_id,
- 'mch_id' => $mch_id,
- 'store_name' => $store_name,
- 'md_id' => $md_id,
- 'role' => [
- 'permissions' => $adminPermission,
- ],
- 'is_saas' => Yii::$app->isSaas(),
- 'is_platform' => false,
- 'is_supplier' => false,
- 'is_dandianpu' => \Yii::$app->prod_is_dandianpu(),
- 'is_expired' => \Yii::$app->isExpired() && \Yii::$app->getAuthSwitch('is_can'),
- 'typename' => $typename
- ];
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $result,
- ]);
- }
- public function actionInfo()
- {
- try {
- $admin = get_admin();
- $mch_id = get_mch_id();
- $supplier_id = get_supplier_id();
- $md_id = get_md_id();
- $mch_brands_id = get_mch_brands_id();
- $is_platform = false; //
- $is_supplier = false;
- $is_area_platform = false;
- $typename = '平台后台';
- if (\Yii::$app->isSaas()) {
- if ($admin->type == Admin::ADMIN_TYPE_MD) {
- $md_id = $admin->type_id;
- }
- if ($md_id > 0) {
- $params = require Yii::$app->basePath . '/config/saas_md_permission.php';
- $md = \app\models\Md::findOne($md_id);
- if ($md && $md->is_single == 0) { // 非独立运营门店去除同城配送
- \Yii::$app->removeMenu($params, ['WechatNewDelivery']);
- }
- } else if ($admin->type == Admin::ADMIN_TYPE_STORE || $admin->type == Admin::ADMIN_TYPE_STAFF) {
- $typename = '商城后台';
- $params = require Yii::$app->basePath . '/config/saas_store_permission.php';
- if (is_open_platform()) {
- //设置小程序配置
- $WechatConfig = \app\models\WechatConfig::findOne(['store_id' => get_store_id()]);
- $store_mini = \app\models\StoreMini::find()->where(['appid' => $WechatConfig->app_id, 'store_id' => get_store_id()])->select('id, appid, authorizer_refresh_token')->one();
- if(empty($store_mini->appid) || empty($store_mini->authorizer_refresh_token)){
- // return [
- // 'code'=>1,
- // 'msg'=>"参数配置错误"
- // ];
- \Yii::$app->removeMenu($params, ['dataStatistic']);
- }
- }
- if($admin->username != 'admin'){
- if ($admin->type == Admin::ADMIN_TYPE_STAFF) {
- $result = null;
- } else {
- $store_id = get_store_id();
- $storeInfo = Store::find()->where(['id'=> $store_id,"is_delete"=>0])->asArray()->one();
- if (!empty($storeInfo['auth']) && $storeInfo['auth'] != '[]') {
- $result = json_decode($storeInfo['auth'], true);
- $mho = Option::get(OptionSetting::MCH_HIDE_OSS, 0, 'saas', '0')['value'];
- if ($mho && \in_array('config_baseConfig_uploadConfig', $result)) {
- // 删除数组中config_baseConfig_uploadConfig
- $result = array_diff($result, ['config_baseConfig_uploadConfig']);
- }
- }
- }
- $adminPermission = AuthRoleForm::getAdminPermission($result);
- //20240816原来是在当前控制器 给挪到AuthRoleForm模型了 这里忘了改了
- $adminPermission = AuthRoleForm::handlePermission($adminPermission);
- }
- } else if ($admin->type == Admin::ADMIN_TYPE_SUPPLIER ) {
- //平台权限
- $is_platform = true;
- //云仓供货商
- $is_supplier = true;
- $typename = '供货商后台';
- $params = require Yii::$app->basePath . '/config/saas_supplier_permission.php';
- } else if ($admin->type == Admin::ADMIN_TYPE_FRONT_AGENT ) {
- //平台权限
- $is_platform = true;
- $typename = '仓库后台';
- $params = require Yii::$app->basePath . '/config/saas_front_agent_permission.php';
- } else if ($admin->type == Admin::ADMIN_TYPE_BD_AGENT ) {
- //平台权限
- $is_platform = true;
- $typename = '推广代理后台';
- $params = require Yii::$app->basePath . '/config/saas_bd_agent_permission.php';
- } else if ($admin->type == Admin::ADMIN_TYPE_GOODS_AGENT ) {
- //平台权限
- $is_platform = true;
- $typename = '线下产品代理后台';
- $params = require Yii::$app->basePath . '/config/saas_goods_agent_permission.php';
- }else if ($admin->type == Admin::ADMIN_TYPE_MCH_BRANDS ) {
- //平台权限
- $is_platform = true;
- $typename = '品牌管理员后台';
- $params = require Yii::$app->basePath . '/config/saas_mch_brands_permission.php';
- $mch_brands_id = $admin->type_id;
- } elseif ($mch_id && $mch_id > 0) {
- $params = require Yii::$app->basePath . '/config/saas_mch_permission.php';
- $typename = '入驻商后台';
- $params = \Yii::$app->filterMenu($params);
- AuthRoleForm::formatPermission($params);
- $result = [];
- AuthRoleForm::getAllPermission($params, $result);
- } else {
- $is_platform = true;
- if ($admin->username != 'admin' && $admin->type != Admin::ADMIN_TYPE_SAAS_STAFF) {
- $typename = '区域代理后台';
- $is_area_platform = true;
- $params = require Yii::$app->basePath . '/config/saas_permission.php';
- } else {
- $params = require Yii::$app->basePath . '/config/saas_admin_permission.php';
- if (!\Yii::$app->prod_is_dandianpu()) {
- //非单店铺时去除商城提现
- // \Yii::$app->removeMenu($params, ['SaasSmsSetting']);
- } else {
- //TODO 12/29老板说让单店铺给放开联盟券设置
- \Yii::$app->removeMenu($params, []);
- }
- if($admin->username != 'admin'){
- $adminPermission = SaasStaffForm::getAdminPermission();
- }
- }
- }
- } else {
- if ($admin->type == Admin::ADMIN_TYPE_MD) {
- $md_id = $admin->type_id;
- }else if ($admin->type == Admin::ADMIN_TYPE_MCH_BRANDS ) {
- //平台权限
- $is_platform = true;
- $typename = '品牌管理员后台';
- $params = require Yii::$app->basePath . '/config/saas_mch_brands_permission.php';
- $mch_brands_id = $admin->type_id;
- }
- $typename = '商城后台';
- if ($mch_id > 0) {
- $params = require Yii::$app->basePath . '/config/saas_mch_permission.php';
- $typename = '入驻商后台';
- } else {
- $params = require Yii::$app->basePath . '/config/permission.php';
- }
- if ($md_id > 0) {
- $typename = '门店后台';
- $params = require Yii::$app->basePath . '/config/saas_md_permission.php';
- }
- }
- \Yii::$app->cache->set('is_platform', $is_platform);
- $params = AuthRoleForm::delEmptyAuth($params);
- if (!$adminPermission) {
- if (
- $admin->username == 'admin' ||
- \Yii::$app->isSaas()
- ) {
- if (\Yii::$app->isSaas() && $admin->type != Admin::ADMIN_TYPE_STAFF) {
- //非独立部署时 去除小程序发布
- \Yii::$app->removeMenu($params, ['uploadWechat','uploadAlipay','storeUpgrade']);
- // 超级管理员 or 入驻商 or 供货商 拥有所有权限
- $params = \Yii::$app->filterMenu($params);
- AuthRoleForm::formatPermission($params);
- $result = [];
- AuthRoleForm::getAllPermission($params, $result);
- $adminPermission = AuthRoleForm::getAdminPermission($result);
- } else {
- if ($admin->username == 'admin') {
- $params = \Yii::$app->filterMenu($params);
- AuthRoleForm::formatPermission($params);
- $result = [];
- AuthRoleForm::getAllPermission($params, $result);
- $adminPermission = AuthRoleForm::getAdminPermission($result);
- } else {
- $adminPermission = AuthRoleForm::getAdminPermission();
- }
- }
- } else {
- if ($admin->type == Admin::ADMIN_TYPE_STAFF) {
- $adminPermission = AuthRoleForm::getAdminPermission();
- } else {
- $params = \Yii::$app->filterMenu($params);
- AuthRoleForm::formatPermission($params);
- $result = [];
- AuthRoleForm::getAllPermission($params, $result);
- $adminPermission = AuthRoleForm::getAdminPermission($result);
- if ($md_id > 0) {
- $params = \Yii::$app->filterMenu($params);
- AuthRoleForm::formatPermission($params);
- $result = [];
- AuthRoleForm::getAllPermission($params, $result);
- $adminPermission = AuthRoleForm::getAdminPermission($result);
- }
- }
- }
- }
- $store_name = '';
- $store = Store::findOne($admin->store_id);
- if ($store) {
- $store_name = $store->name;
- }
- $result = [
- 'type' => $admin->type,
- 'typename' => $typename,
- 'mch_id' => $mch_id,
- 'mch_brands_id' => $mch_brands_id,
- 'username' => $admin->username,
- 'name' => $admin->name,
- 'mobile' => $admin->mobile,
- 'email' => $admin->email,
- 'remark' => $admin->remark,
- 'avatar' => $admin->avatar ?: '/avatar2.jpg',
- 'store_id' => $admin->store_id,
- 'store_name' => $store_name,
- 'md_id' => $md_id,
- 'role' => [
- 'permissions' => $adminPermission,
- ],
- 'is_saas' => Yii::$app->isSaas(),
- 'is_platform' => $is_platform,
- 'is_supplier' => $is_supplier,
- 'is_dandianpu' => \Yii::$app->prod_is_dandianpu(),
- 'is_expired' => \Yii::$app->isExpired() && \Yii::$app->getAuthSwitch('is_can'),
- 'is_area_platform' => $is_area_platform,
- ];
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $result,
- ]);
- } catch (\Throwable $throwable) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => 'error',
- 'data' => $throwable->getMessage(),
- 'line' => $throwable->getLine(),
- 'file' => $throwable->getFile()
- ]);
- }
- }
- /**
- * 用户列表
- * @return \yii\web\Response
- */
- public function actionList() {
- $userForm = new UserForm();
- $userForm->attributes = get_params();
- $store_id = get_store_id();
- $userForm->store_id = $store_id;
- return $this->asJson($userForm->getUserList());
- }
- /**
- * 更新用户信息
- * @return \yii\web\Response
- * @throws \yii\base\Exception
- */
- public function actionUpdateInfo() {
- $userForm = new UserForm();
- $userForm->store_id = get_store_id();
- $userForm->attributes = post_params();
- return $this->asJson($userForm->updateUserInfo());
- }
- /**
- * 会员等级
- */
- public function actionLevelList()
- {
- $form = new LevelForm();
- $form->store_id = get_store_id();
- $form->attributes = get_params();
- return $this->asJson($form->search());
- }
- /**
- * 获取所有会员等级
- */
- public function actionAllLevelList()
- {
- $form = new LevelForm();
- $form->store_id = get_store_id();
- $form->attributes = get_params();
- return $this->asJson($form->getAllLevelList());
- }
- /**
- * 获取所有会员等级
- */
- public function actionSelectLevel()
- {
- $form = new \app\modules\admin\models\AccountLogForm();
- $form->store_id = get_store_id();
- $list = $form->getLevelList();
- return $this->asJson([
- 'code' => 0,
- 'data' => $list,
- ]);
- }
- /**
- * 会员等级启用/禁用
- */
- public function actionLevelStatus()
- {
- $data = post_params();
- $store_id = get_store_id();
- $level = Level::find()->where(['id' => $data['id'], 'store_id' => $store_id])->one();
- if (!$level) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '会员等级不存在',
- ]);
- }
- $level->status = $data['status'];
- if ($data['status'] == Level::STATUS_FALSE) {
- $exit = User::find()->where(['store_id' => $store_id, 'level' => $level->level])->exists();
- if ($exit) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '该会员等级下有会员,不可禁用',
- ]);
- }
- }
- if ($level->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '成功',
- ]);
- } else {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '网络异常',
- ]);
- }
- }
- /**
- * 会员等级启用/禁用
- */
- public function actionLevelStudent()
- {
- $data = post_params();
- $store_id = get_store_id();
- $level = Level::find()->where(['id' => $data['id'], 'store_id' => $store_id])->one();
- if (!$level) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '会员等级不存在',
- ]);
- }
- if ($data['is_student'] == Level::STUDENT_TRUE) {
- Level::updateAll(['is_student' => 0]);
- }
- $level->is_student = $data['is_student'];
- if ($level->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '成功',
- ]);
- } else {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '网络异常',
- ]);
- }
- }
- public function actionGetLevelItem(){
- $data = get_params();
- $levelForm = new LevelForm();
- $levelForm->id = $data['id'];
- return $this->asJson($levelForm->getLevelItem());
- }
- /**
- * 更新会员等级信息
- * @return \yii\web\Response
- */
- public function actionUpdateLevelInfo() {
- $data = post_params();
- $store_id = get_store_id();
- if (!empty($data['id'])) {
- $level = Level::findOne(['id' => $data['id'], 'is_delete' => Level::NOT_DELETE, 'store_id' => $store_id]);
- } else {
- $level = new Level();
- }
- $levelForm = new LevelForm();
- $levelForm->scenario = 'edit';
- $levelForm->model = $level;
- $levelForm->store_id = $store_id;
- $levelForm->attributes = $data;
- return $this->asJson($levelForm->save());
- }
- /**
- * 会员等级删除
- */
- public function actionDeleteLevel()
- {
- $data = post_params();
- $store_id = get_store_id();
- $level = Level::findOne(['id' => $data['id'], 'store_id' => $store_id, 'is_delete' => Level::NOT_DELETE]);
- if (!$level) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '会员等级不存在',
- ]);
- }
- $exit = User::find()->where(['store_id' => $store_id, 'level' => $level->level])->exists();
- if ($exit) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '该会员等级下有会员,不可删除',
- ]);
- }
- $level->is_delete = 1;
- if ($level->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '成功',
- ]);
- } else {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '网络异常',
- ]);
- }
- }
- /**
- * 会员购买记录
- */
- public function actionLevelOrder()
- {
- $params = get_params();
- $store_id = get_store_id();
- if ($params['user_id']) {
- $query = LevelOrder::find()->alias('ro')->where(['ro.store_id' => $store_id,
- 'ro.is_delete' => LevelOrder::NOT_DELETE, 'ro.is_pay' => LevelOrder::IS_PAY])
- ->leftJoin(['u' => User::tableName()], 'u.id='.$params['user_id'])
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding');
- } else {
- $query = LevelOrder::find()->alias('ro')->where(['ro.store_id' => $store_id,
- 'ro.is_delete' => LevelOrder::NOT_DELETE, 'ro.is_pay' => LevelOrder::IS_PAY])
- ->leftJoin(['u' => User::tableName()], 'u.id=ro.user_id')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding');
- }
- if (!empty($params['keyword'])) {
- $query->andWhere(['like', 'u.nickname', $params['keyword']]);
- }
- if (!empty($params['dateStart'])) {
- $query->andWhere(['>', 'ro.created_at', strtotime($params['dateStart'])]);
- }
- if (!empty($params['dateEnd'])) {
- $query->andWhere(['<', 'ro.created_at', strtotime($params['dateEnd'])]);
- }
- $currentQuery = Level::find()->where(['store_id' => $store_id, 'is_delete' => Level::NOT_DELETE])
- ->andWhere('level=ro.current_level')->select('name');
- $afterQuery = Level::find()->where(['store_id' => $store_id,'is_delete' => Level::NOT_DELETE])
- ->andWhere('level=ro.after_level')->select('name');
- $query->select(['ro.*', 'su.name as nickname', 'u.platform', 'after_name' => $afterQuery, 'current_name' => $currentQuery])->orderBy('ro.id desc');
- $pagination = pagination_make($query);
- $list = $pagination['list'];
- foreach ($list as $k => $v) {
- $list[$k]['pay_time'] = date('Y-m-d H:i:s', $v['pay_time']);
- if (!$v['current_name']) {
- $list[$k]['current_name'] = '普通会员';
- }
- $list[$k]['share_money_log'] = UserShareMoney::find()->alias('usm')
- ->leftJoin(['u' => User::tableName()], 'usm.user_id = u.id')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding')
- ->where(['usm.order_id' => $v['id'], 'usm.order_type' => UserShareMoney::LEVEL_ORDER_TYPE, 'usm.is_delete' => 0])
- ->select('u.id, su.name, su.avatar, usm.money, usm.desc, usm.created_at')->orderBy('usm.created_at')->asArray()->all();
- }
- $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list,
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount']
- ],
- ]);
- }
- /**
- * 获取用户列表(saas_user)
- */
- public function actionSelectList()
- {
- $type = get_params("type");
- $scene = get_params("scene");
- $admin = get_admin();
- $keyword = get_params('keyword');
- if ((($admin->type === 'admin' && $admin->username !== 'admin') || $admin->type === 'bd_agent') && empty($keyword)) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => [],
- 'status' => 1,
- 'pageNo' => 0,
- 'totalCount' => 0
- ],
- ]);
- }
- $mobiles = [];
- //排除推荐人
- if ($type === "user" && $scene === "recommend") {
- $mobiles = Salesman::find()->alias('s')->where(['s.is_delete'=>0])
- ->leftJoin(['su'=>SaasUser::tableName()],'s.saas_user_id = su.id')
- ->select("su.mobile")->column();
- }
- $select = 'su.name, su.id, su.avatar';
- if ($type === "u_id") {
- $select = 'u.nickname as name, u.id, u.avatar_url as avatar';
- }
- //用户
- $store_id = get_params('storeId', get_store_id());
- $query = User::find()->where(['u.is_delete' => 0, 'u.store_id' => $store_id])->alias('u')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding')
- ->andWhere(['and', ['not', ['u.nickname' => '']], ['not', ['su.name' => '']],['not in','binding',$mobiles], ['<>','binding','']])->select($select);
- if (!empty(get_params('keyword'))) {
- if($type === "u_id"){
- $query->andWhere(['like', 'u.nickname', get_params('keyword')]);
- }else{
- $query->andWhere(['like', 'su.name', get_params('keyword')]);
- }
- }
- //筛选有公众号openid的用户
- if ($scene === "hasMpOpenid") {
- $query->andWhere(['!=', 'wechat_platform_open_id', ''])
- ->addSelect(['wechat_platform_open_id']);
- }
- //选择股东
- if ($type === "shareHolder") {
- $query = ShareHolder::find()->alias('sh')->where(['sh.is_delete' => 0, 'sh.store_id' => $store_id])
- ->leftJoin(['u' => User::tableName()], 'sh.user_id = u.id')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile = u.binding')
- ->andWhere(['and', ['<>', 'u.nickname', ''], ['<>', 'sh.name', ''],['not in','u.binding',$mobiles]])
- ->select('su.name, u.id, u.price, su.avatar');
- if (!empty(get_params('keyword'))) {
- $query->andWhere(['OR', ['like', 'sh.name', get_params('keyword')], ['like', 'su.mobile', get_params('keyword')]]);
- }
- }
- //选择股东
- if ($type === "admin") {
- if (empty($scene)) {
- $scene = 'admin';
- }
- $query = Admin::find()->alias('a')->where(['a.is_delete' => 0, 'a.type' => $scene])
- ->leftJoin(['su' => SaasUser::tableName()], 'su.id = a.saas_user_id')
- // ->leftJoin(['u' => User::tableName()], 'u.binding = su.mobile')
- ->andWhere(['and', ['<>', 'a.name', ''],['<>','a.id',1]])
- ->select('a.username name, a.id, su.avatar')->groupBy('su.id');
- if (!empty(get_params('keyword'))) {
- $query->andWhere(['like', 'a.name', get_params('keyword')]);
- }
- //var_dump($query->createCommand()->getRawSql());die;
- }
- //股东
- if ($type === "user" && $scene === "shareHolder") {
- //排除股东
- $mobiles = ShareHolder::find()->alias('sh')->where(['sh.is_delete'=>0, 'sh.store_id' => get_store_id()])
- ->leftJoin(['u'=>User::tableName()],'sh.user_id = u.id')
- ->select("u.binding")->column();
- $query = User::find()->where(['u.is_delete' => 0, 'u.store_id' => $store_id])->alias('u')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding')
- ->andWhere(['and', ['not', ['u.nickname' => '']], ['not', ['su.name' => '']],['not in','binding',$mobiles]])->select('su.name, u.id, su.avatar');
- if (!empty(get_params('keyword'))) {
- $query->andWhere(['OR', ['like', 'su.name', get_params('keyword')], ['like', 'su.mobile', get_params('keyword')]]);
- }
- $query->groupBy('u.id');
- }
- //股东
- if ($type === "area" && $scene === "shareHolder") {
- //排除股东
- $share_holder_user_id = ShareHolder::find()->where(['is_delete' => 0, 'store_id' => $store_id])->andWhere(['>', 'agent_type', 0])
- ->select("user_id")->column();
- $query = User::find()->where(['u.is_delete' => 0, 'u.store_id' => $store_id])->alias('u')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding')
- ->andWhere(['and', ['not', ['u.nickname' => '']], ['not', ['su.name' => '']],['NOT IN','u.id',$share_holder_user_id]])
- ->select('su.name, u.id, su.avatar');
- if (!empty(get_params('keyword'))) {
- $query->andWhere(['OR', ['like', 'su.name', get_params('keyword')], ['like', 'su.mobile', get_params('keyword')]]);
- }
- $query->groupBy('u.id');
- }
- //分销商
- if ($type === "share") {
- $query = User::find()->where(['u.is_delete' => 0, 'u.store_id' => $store_id, 'u.is_distributor' => 0])->alias('u')
- ->andWhere( ['not', ['u.nickname' => '']])->select('u.nickname as name, u.id, u.avatar_url as avatar');
- if (!empty(get_params('keyword'))) {
- $query->andWhere(['like', 'u.nickname', get_params('keyword')]);
- }
- $query->groupBy('u.id');
- }
- //联盟用户
- if ($type === 'user' && empty($scene)) {
- $query = SaasUser::find()->where(['is_delete' => 0])
- ->select('name, id, avatar, mobile');
- if (!empty(get_params('keyword'))) {
- $query->andWhere(['OR', ['like', 'name', get_params('keyword')], ['like', 'mobile', get_params('keyword')]]);
- }
- }
- //业务员
- if ($type === 'user' && $scene === "user") {
- $user_id = Salesman::find()->where(['is_delete' => 0])->select('saas_user_id')->column();
- $query = SaasUser::find()->where(['is_delete' => 0])->andWhere(['not in', 'id', $user_id])
- ->select('name, id, avatar');
- }
- //服务人员
- if ($type === 'user' && $scene === "worker") {
- $user_id = Worker::find()->where(['status' => [0, 1]])->select('user_id')->column();
- $query = User::find()->alias('u')->leftJoin(['su' => SaasUser::tableName()], 'u.binding = su.mobile')
- ->where(['su.is_delete' => 0, 'u.store_id' => get_store_id(), 'u.is_delete' => 0])->andWhere(['not in', 'u.id', $user_id])
- ->select('su.name, u.id, su.avatar')->orderBy('id desc');
- if (!empty(get_params('keyword'))) {
- $query->andWhere(['OR', ['like', 'su.name', get_params('keyword')], ['like', 'su.mobile', get_params('keyword')]]);
- }
- }
- /* 2023年6月29日18:04:05 begin WPing id891新增功能 */
- //排除配送员
- if ($type === "user" && $scene === "courier") {
- $mobiles = LocalDeliveryCourier::find()->alias('c')->where(['c.is_delete'=>0])
- ->leftJoin(['su'=>SaasUser::tableName()],'c.saas_user_id = su.id')
- ->select("su.mobile")->column();
- $query = SaasUser::find()->where(['is_delete' => 0])->where(['not in','mobile',$mobiles])
- ->select('name, id, avatar, mobile');
- if (!empty(get_params('keyword'))) {
- $query->andWhere(['OR', ['like', 'name', get_params('keyword')], ['like', 'mobile', get_params('keyword')]]);
- }
- }
- //选择配送员
- if ($type === "courier") {
- $query = LocalDeliveryCourier::find()->alias('c')->where(['c.is_delete' => 0, 'status' => 1, 'state' => 2])
- ->leftJoin(['su' => SaasUser::tableName()], 'c.saas_user_id = su.id')
- ->andWhere(['<>', 'c.real_name', ''])
- ->select('c.real_name, c.id, su.avatar, c.mobile, c.max_num');
- if (!empty(get_params('keyword'))) {
- $query->andWhere(['OR', ['like', 'c.real_name', get_params('keyword')], ['like', 'c.mobile', get_params('keyword')]]);
- }
- if ($store_id > 0) {
- $query->andWhere(['c.store_id' => $store_id, 'type' => 2]);
- } else {
- $query->andWhere(['type' => 1]);
- }
- }
- if ($type === "bd_agent") {
- $db_agent = Admin::find()->where(['type' => Admin::ADMIN_TYPE_BD_AGENT, 'is_delete' => 0])->select('saas_user_id')->column();
- $query = SaasUser::find()->where(['is_delete' => 0])->andWhere(['AND', ['<>', 'name', ''], ['not in', 'id', $db_agent]])
- ->select('name, id, avatar, mobile');
- if (!empty(get_params('keyword'))) {
- $query->andWhere(['like', 'name', get_params('keyword')]);
- }
- }
- /* end */
- // 搜索品牌分类管理员
- if($type === "u_id" && $scene === "mch-brands-user"){
- // 排出已绑定的品牌分类管理员
- $has = MchBrands::find()->where(['store_id' => $store_id, 'is_delete' => 0])->select('user_id')->column();
- $query = User::find()->where(['u.is_delete' => 0, 'u.store_id' => $store_id])->alias('u')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding')
- ->andWhere(['and', ['not', ['u.nickname' => '']], ['not', ['su.name' => '']],['not in','u.id',$has]])->select('u.nickname, u.id, u.avatar_url');
- if (!empty(get_params('keyword'))) {
- $query->andWhere(['OR', ['like', 'u.nickname', get_params('keyword')], ['like', 'u.binding', get_params('keyword')]]);
- }
- $query->groupBy('u.id');
- }
- // 入住商员工
- if($type === "u_id" && $scene === "mch-staff-user"){
- // 排出已绑定的品牌分类管理员
- $has = MchStaff::find()->where(['store_id' => $store_id, 'is_delete' => 0])->select('user_id')->column();
- $query = User::find()->where(['u.is_delete' => 0, 'u.store_id' => $store_id])->alias('u')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding')
- ->andWhere(['and', ['not', ['u.nickname' => '']], ['not', ['su.name' => '']],['not in','u.id',$has]])->select('u.nickname, u.id, u.avatar_url');
- if (!empty(get_params('keyword'))) {
- $query->andWhere(['OR', ['like', 'u.nickname', get_params('keyword')], ['like', 'u.binding', get_params('keyword')]]);
- }
- $query->groupBy('u.id');
- }
- $pagination = pagination_make($query);
- if($type === "u_id" && $scene === "mch-staff-user"){
- // 排出入住商管理员
- $hasMch = Mch::find()->where(['is_delete'=>0,'store_id' => $store_id])->select('user_id')->column();
- foreach($pagination['list'] as &$item){
- $item['is_disable'] = in_array($item['id'],$hasMch) ? 1 : 0;
- }
- }
- if ($type === "courier") {
- foreach($pagination['list'] as &$v) {
- $now_num = DeliveryInfo::find()->alias('di')
- ->leftJoin(['o' => Order::tableName()], 'di.order_no = o.order_no')
- ->where(['o.trade_status' => 2, 'is_local' => 1, 'rider_id' => $v['id']])
- ->count();
- $v['now_order_status'] = $v['max_num'] == 0 ? '无限制' : $now_num.'/'.$v['max_num'];
- }
- }
- //增加分享员逻辑
- if ($scene === 'share') {
- foreach($pagination['list'] as &$v) {
- $share = Share::findOne(['user_id' => $v['id'], 'store_id' => get_store_id(), 'is_delete' => 0]);
- $v['level'] = $share->level ?: 0;
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $pagination['list'],
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount']
- ],
- ]);
- }
- // 获取user表用户列表
- public function actionGetUserList()
- {
- $type = get_params("type", 'user');
- if ($type == 'shareholder') {
- $parentId = \get_params('parent_id', -1);
- $query = User::find()->alias('u')
- ->where(['u.is_delete' => 0, 'u.store_id' => get_store_id(), 'u.is_holder' => 1])
- ->andWhere(['not', ['u.nickname' => '']])
- ->select('u.id, u.avatar_url avatar, u.nickname name');
- if (!empty(get_params('keyword'))) {
- $query->andWhere(['like', 'u.nickname', get_params('keyword')]);
- }
- if ($parentId > -1) {
- $query->andWhere(['u.old_parent_id' => $parentId]);
- $query->andWhere(['<>', 'u.id', $parentId]);
- }
- $pagination = pagination_make($query);
- } else {
- $query = User::find()->alias('u')
- ->leftJoin(['su' => SaasUser::tableName()], 'u.binding=su.mobile')
- ->where(['u.is_delete' => 0, 'u.store_id' => get_store_id()])
- ->andWhere(['not', ['u.nickname' => '']])
- ->andWhere(['AND', ['<>', 'u.binding', ''], ['su.is_delete' => 0]])
- ->select('u.id, u.avatar_url avatar, u.nickname name');
- if (!empty(get_params('keyword'))) {
- $query->andWhere(['OR', ['like', 'u.nickname', get_params('keyword')], ['like', 'u.binding', get_params('keyword')]]);
- }
- $pagination = pagination_make($query);
- if($pagination['pageNo'] == 1){
- $temp[0] = ['id'=>0,'avatar'=>'','name'=>'总店'];
- $pagination['list'] = array_merge($temp,$pagination['list']);
- }
- }
- $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $pagination['list'],
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount']
- ],
- ]);
- }
- /**
- * 管理员列表
- * @return \yii\web\Response
- */
- public function actionAdminUser() {
- $userForm = new UserForm();
- $userForm->attributes = get_params();
- // $userForm->is_admin = get_params('is_admin', 0);
- $store_id = get_store_id();
- $userForm->store_id = $store_id;
- return $this->asJson($userForm->getUserList());
- }
- /**
- * 添加管理员
- * @return \yii\web\Response
- */
- public function actionAddAdmin() {
- try {
- $user = User::findOne(['id' => get_params('id'), 'store_id' => get_store_id()]);
- //查询是否已经绑定商城管理员
- if (empty($user->binding)) {
- throw new \Exception('添加失败,用户未绑定手机号,请更换用户或使用手机端重新登录更新手机号信息');
- }
- $saas_user = SaasUser::findOne(['mobile' => $user->binding, 'is_delete' => 0]);
- $user_admin = User::find()->where(['binding' => $saas_user->mobile, 'is_delete' => 0, 'is_admin' => 1])->one();
- if ($user_admin) {
- throw new \Exception('添加失败,用户已经绑定其他商城管理员');
- } else {
- $admin = Admin::find()->where(['or',
- ['saas_user_id' => $saas_user->id],
- ['mobile' => $saas_user->mobile]])->andWhere(['is_delete' => 0, 'type' => 'store'])->one();
- if ($admin) {
- throw new \Exception('添加失败,用户已经绑定其他商城管理员');
- }
- $store_audit = StoreAudit::findOne(['saas_user_id' => $saas_user->id]);
- if ($store_audit) {
- throw new \Exception('添加失败,用户已经绑定其他商城管理员');
- }
- }
- $user->is_admin = 1;
- if ($user->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '添加成功'
- ]);
- } else {
- throw new \Exception('添加失败');
- }
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- }
- /**
- * 删除管理员
- * @return \yii\web\Response
- */
- public function actionDelAdmin() {
- $userForm = new UserForm();
- $userForm->attributes = get_params();
- $store_id = get_store_id();
- $userForm->store_id = $store_id;
- return $this->asJson($userForm->delAdmin());
- }
- /**
- * 设置推荐人
- */
- public function actionSetParent()
- {
- $user_id = post_params('user_id');
- $parent_id = post_params('parent_id', 0);
- if (!$user_id) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数错误',
- ]);
- }
- $user = User::findOne($user_id);
- if (!$user) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '用户未找到',
- ]);
- }
- if ($parent_id > 0) {
- $parent = User::find()->where([
- 'id' => $parent_id,
- 'store_id' => $user->store_id,
- ])->one();
- if (!$parent) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '推荐人未找到',
- ]);
- }
- }
- $user->parent_id = $parent_id;
- $user->old_parent_id = $parent_id;
- $user->save();
- return $this->asJson([
- 'code' => 0,
- 'msg' => '保存成功',
- ]);
- }
- /**
- * 用户默认设置
- */
- public function actionUserDefaultInfo() {
- return;
- if (\Yii::$app->request->isPost) {
- $data = post_params();
- if (intval($data['isOpenDefault']) &&
- (empty($data['default_user_nickname']) || empty($data['default_user_pic']))
- ) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请填写头像和昵称',
- ]);
- }
- Option::set('default_user_info', Json::encode($data), get_store_id(), 'store');
- return $this->asJson([
- 'code' => 0,
- 'msg' => '修改成功',
- ]);
- }
- $baseUrl = \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl;
- $wxappUrl = $baseUrl . '/web/v1/statics/clientImg';
- $default = Json::encode(['default_user_nickname' => '微信用户', 'default_user_pic' => $wxappUrl . '/default_wechat_avatar.jpeg']);
- $option = Option::get('default_user_info', get_store_id(), 'store', $default);
- $default_info = Json::decode($option['value']);
- $default_info['default_user_nickname'] = $default_info['default_user_nickname'] ?: '微信用户';
- $default_info['default_user_pic'] = $default_info['default_user_pic'] ?: $wxappUrl . '/default_wechat_avatar.jpeg';
- return $this->asJson([
- 'code' => 0,
- 'data' => $default_info,
- 'msg' => '',
- ]);
- }
-
- //设置用户收货地址
- public function actionSetUserAddress() {
- $form = new UserForm();
- $form->attributes = post_params();
- $form->is_default = post_params('is_default', 0);
- $form->store_id = get_store_id();
- return $this->asJson($form->addAddress());
- }
- //设置用户收货地址(0=设置默认 1=删除)
- public function actionSetUserAddressStatus() {
- $form = new UserForm();
- $form->attributes = post_params();
- $form->is_default = post_params('is_default', 0);
- $form->store_id = get_store_id();
- return $this->asJson($form->setUserAddressStatus());
- }
- //获取用户收货地址
- public function actionGetUserAddress() {
- $form = new UserForm();
- $form->attributes = get_params();
- return $this->asJson($form->getUserAddress());
- }
- //获取用户佣金
- public function actionUserPriceData() {
- $id = input_params('id');
- $mobile = input_params('mobile');
- $name = input_params('name');
- $store_id = get_store_id();
- $query = User::find()->where(['store_id' => $store_id])->orderBy("id desc");
- $queryCount = clone $query;
- if ($id) {
- $query->andWhere(['id' => $id]);
- }
- if ($mobile) {
- $query->andWhere(['like', 'binding', $mobile]);
- }
- $query->andWhere(['!=', 'binding', '']);
- if ($name) {
- $query->andWhere(['binding' => SaasUser::find()->where(['like', 'name', $name])->select('mobile')]);
- }
- $query->select('id, binding, total_price, price');
- $list = pagination_make($query);
- foreach($list['list'] as &$item){
- $su = SaasUser::findOne(['mobile' => $item['binding']]);
- $item['name'] = $su['name'];
- $item['avatar'] = $su['avatar'];
- $item['userCashSum'] = floor_num(\app\models\Cash::find()->where(['is_delete' => 0, 'user_id' => $item['id'], 'status' => 2])->andWhere(['!=', 'cash_type', 2])->sum('price'));
- $team = new \app\modules\client\models\v1\TeamForm();
- $team->user_id = $item['id'];
- $team->store_id = $store_id;
- $arr = $team->getOrderCount();
- $item['order_money_un'] = floor_num($arr['order_money_un']);
- }
-
- if($list['pageNo'] == 1){
- $count = [];
- $count['userCount'] = (int)$queryCount->count();
- $count['userPriceSum'] = (int)$queryCount->sum('price');
- $count['userCashSum'] = floor_num(\app\models\Cash::find()->where(['is_delete' => 0, 'store_id' => $store_id, 'status' => 2])->andWhere(['!=', 'cash_type', 2])->sum('price'));
- $count['order_money_un'] = floor_num(array_sum(Order::find()->where(['store_id' => $store_id, 'trade_status' => [0, 2, 3], 'is_sale' => 0])
- ->select('SUM(limit_price), SUM(rebate), SUM(first_price), SUM(second_price), SUM(third_price)')
- ->addSelect('SUM(holder_first_price), SUM(holder_second_price), SUM(holder_third_price)')
- ->addSelect('SUM(old_holder_first_price), SUM(old_holder_second_price), SUM(old_holder_third_price)')
- ->asArray()->one()));
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $list,
- 'count' => $count,
- ]);
- }
- //获取用户提现
- public function actionUserCashLog() {
- $user_id = input_params('user_id');
- $user = User::findOne($user_id);
- $su = SaasUser::findOne(['mobile' => $user['binding']]);
- $store_id = get_store_id();
- $query = \app\models\Cash::find()->alias('c')->where(['c.is_delete' => 0, 'c.user_id' => $user_id, 'c.status' => 2])->andWhere(['!=', 'cash_type', 2]);
- $list = pagination_make($query);
- foreach($list['list'] as &$item){
- $item['name'] = $su['name'];
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $list,
- ]);
- }
- //获取用户未到账佣金
- public function actionUserPriceOrderLog() {
- $user_id = input_params('user_id');
- $user = User::findOne($user_id);
- $su = SaasUser::findOne(['mobile' => $user['binding']]);
- $store_id = get_store_id();
- $team = new \app\modules\client\models\v1\TeamForm();
- $team->user_id = $user_id;
- $team->store_id = $store_id;
- $team->status = 1;
- $res = $team->getOrder();
- return $this->asJson($res);
- }
- //获取用户佣金
- public function actionUserPriceLog() {
- $user_id = input_params('user_id');
- $user = User::findOne($user_id);
- $su = SaasUser::findOne(['mobile' => $user['binding']]);
- $store_id = get_store_id();
- $query = UserShareMoney::find()->alias('usm')
- ->leftJoin(['o' => Order::tableName()], 'usm.order_id = o.id')
- ->leftJoin(['u' => User::tableName()], 'o.user_id = u.id')
- ->leftJoin(['su' => SaasUser::tableName()], 'u.binding = su.mobile')
- ->where(['usm.user_id' => $user_id])->orderBy("usm.id desc");
- $query->select('usm.*, o.order_no, o.total_price order_total_price, su.name order_user_name');
- $list = pagination_make($query);
- foreach($list['list'] as &$item){
- $item['name'] = $su['name'];
- $item['source_name'] = UserShareMoney::SOURCE_NAME[$item['source']] ?? '--';
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $list,
- ]);
- }
- //获取用户余额
- public function actionUserMoneyData() {
- $id = input_params('id');
- $mobile = input_params('mobile');
- $name = input_params('name');
- $store_id = get_store_id();
- $query = User::find()->where(['store_id' => $store_id])->orderBy("id desc");
- $queryCount = clone $query;
- if ($id) {
- $query->andWhere(['id' => $id]);
- }
- if ($mobile) {
- $query->andWhere(['like', 'binding', $mobile]);
- }
- $query->andWhere(['!=', 'binding', '']);
- if ($name) {
- $query->andWhere(['binding' => SaasUser::find()->where(['like', 'name', $name])->select('mobile')]);
- }
- $query->select('id, binding, money');
- $list = pagination_make($query);
- foreach($list['list'] as &$item){
- $su = SaasUser::findOne(['mobile' => $item['binding']]);
- $item['name'] = $su['name'];
- $item['avatar'] = $su['avatar'];
- $item['userRechargeSum'] = floor_num(\app\models\ReOrder::find()->where(['is_delete' => 0, 'user_id' => $item['id'], 'is_pay' => 1])->sum('pay_price'));
- }
-
- if($list['pageNo'] == 1){
- $count = [];
- $count['userCount'] = (int)$queryCount->count();
- $count['userMoneySum'] = floor_num($queryCount->sum('money'));
- $count['userRechargeSum'] = floor_num(\app\models\ReOrder::find()->where(['is_delete' => 0, 'store_id' => $store_id, 'is_pay' => 1])->sum('pay_price'));
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $list,
- 'count' => $count,
- ]);
- }
- //获取佣金 余额 积分 转赠记录
- public function actionGetAccountLog() {
- try {
- $type = (int)get_params('type', 0);
- $log_type = get_params('log_type');
- $user_name = get_params('user_name');
- $from_user_name = get_params('from_user_name');
- $start_time = get_params('start_time');
- $end_time = get_params('end_time');
- $store_id = get_store_id();
- switch ($type) {
- case 1: //余额 且 赠送
- $type = 2;
- $from = [1, 2];
- break;
- case 2://余额 且 佣金转
- $type = 2;
- $from = 3;
- break;
- default: //积分 且 赠送
- $type = 1;
- $from = [1, 2];
- break;
- }
- $query = AccountLog::find()->where([
- 'store_id' => $store_id,
- 'type' => $type, // 余额
- 'from' =>$from
- ]);
- if (in_array($log_type, [1, 2])) {
- $query->andWhere(['log_type' => $log_type]);
- }
- if($user_name){
- $user_id = User::find()->alias('u')->leftJoin(['su' => SaasUser::tableName()], 'u.binding = su.mobile')
- ->where(['u.store_id' => $store_id])->andWhere(['like', 'su.name', $user_name])->select('u.id');
- $query->andWhere(['user_id' => $user_id]);
- }
- if($from_user_name){
- $user_id = User::find()->alias('u')->leftJoin(['su' => SaasUser::tableName()], 'u.binding = su.mobile')
- ->where(['u.store_id' => $store_id])->andWhere(['like', 'su.name', $from_user_name])->select('u.id');
- $query->andWhere(['from_user_id' => $user_id]);
- }
- if (!empty($start_time)) {
- $query->andWhere(['>' , 'created_at', strtotime($start_time)]);
- }
- if (!empty($end_time)) {
- $query->andWhere(['<' , 'created_at', strtotime($end_time)]);
- }
- $query->orderBy('id DESC');
- $list = pagination_make($query);
- $userIds = array_unique(array_merge(array_column($list['list'], 'user_id'), array_column($list['list'], 'from_user_id')));
- $arr = User::find()->alias('u')->leftJoin(['su' => SaasUser::tableName()], 'u.binding = su.mobile')
- ->where(['u.store_id' => $store_id, 'u.id' => $userIds])->select('u.id, su.name, su.mobile, su.avatar')->asArray()->all();
- $users = array_combine(array_column($arr, 'id'), $arr);
- foreach ($list['list'] as &$value) {
- $value['date'] = date('Y-m-d H:i:s', $value['created_at']);
- $value['content'] = $value['desc'];
- $value['money_base'] = $value['amount'];
- $value['money_received'] = $value['amount'];
- if($value['from'] == 1){
- $value['money_received'] = $value['amount'] - $value['profit'];
- }
- if($value['from'] == 2){
- $value['money_base'] = $value['amount'] + $value['profit'];
- }
- if($value['from'] == 3){
- $value['money_base'] = $value['amount'] + $value['profit'];
- }
- $value['user'] = $users[$value['user_id']];
- $value['from_user'] = $users[$value['from_user_id']];
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $list,
- 'q' => $query->createCommand()->getRawSql(),
- ]);
- }catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- }
- //月付客户额度设置
- public function actionMoneyMonthSet() {
- $user_id = input_params('user_id');
- if(!is_array($user_id)){
- $user_id = explode(',', $user_id);
- }
- $money_month = input_params('money_month');
- if($money_month <= 0){
- return $this->asJson([
- 'code' => 1,
- 'msg' => '额度数值错误',
- ]);
- }
- $update = User::updateAll(['money_month' => $money_month], ['id' => $user_id, 'store_id' => get_store_id()]);
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操作成功,修改数据' . $update . '条',
- ]);
- }
- //月付客户删除
- public function actionMoneyMonthDel() {
- $user_id = input_params('user_id');
- if(!is_array($user_id)){
- $user_id = explode(',', $user_id);
- }
- $user_err = User::find()->where(['id' => $user_id])->andWhere(['!=', 'money_month_used', 0])->limit(1)->one();
- if($user_err){
- return $this->asJson([
- 'code' => 1,
- 'msg' => '操作失败,存在已用额度非零用户:' . $user_err->binding,
- ]);
- }
- $update = User::updateAll(['money_month' => 0], ['id' => $user_id, 'store_id' => get_store_id()]);
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操作成功,修改数据' . $update . '条',
- ]);
- }
- //月付客户还款
- public function actionMoneyMonthRepay() {
- $user_id = input_params('user_id');
- $money = input_params('money');
- $user = User::findOne(['id' => $user_id, 'store_id' => get_store_id()]);
- if($user->money_month_used == 0){
- return $this->asJson([
- 'code' => 1,
- 'msg' => '操作失败,未使用额度,无需还款',
- ]);
- }
- $res = UserPayMonth::repay($user->id, $money);
- return $this->asJson($res);
- }
- //月付客户额度记录
- public function actionMoneyMonthLog() {
- $store_id = get_store_id();
- $type = input_params('type');
- $user_id = input_params('user_id');
- $begin_time = input_params('begin_time');
- $end_time = input_params('end_time');
- $query = UserPayMonth::find()->where(['store_id' => $store_id]);
- if(isset($user_id) && $user_id > 0){
- $query->andWhere(['user_id' => $user_id]);
- }
- if(isset($type) && $type > -1){
- $query->andWhere(['type' => $type]);
- }
- if($begin_time){
- $query->andWhere(['>=', 'created_at', strtotime($begin_time . ' 00:00:00')]);
- }
- if($end_time){
- $query->andWhere(['<=', 'created_at', strtotime($end_time . ' 23:59:59')]);
- }
- $querySum = clone $query;
- $sumMoney = $querySum->sum('money');
- $query->orderBy('id DESC');
- $data = pagination_make($query);
- return $this->asJson([
- 'q' => $query->createCommand()->getRawSql(),
- 'code' => 0,
- 'msg' => 'ok',
- 'data' => $data,
- 'sumMoney' => $sumMoney,
- ]);
- }
- public function actionUserInfo() {
- $userForm = new UserForm();
- $userForm->attributes = all_params();
- $store_id = get_store_id();
- $userForm->store_id = $store_id;
- $userForm->user_id = input_params('user_id');
- $res = $userForm->getUserList();
- if(!$res['data']['data']){
- return $this->asJson([
- 'code' => 1,
- 'msg' => '用户不存在',
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'ok',
- 'data' => $res['data']['data'][0],
- ]);
- }
- public function actionGetUserPrice() {
- $userForm = new UserForm();
- $userForm->attributes = get_params();
- $userForm->store_id = get_store_id();
- return $this->asJson($userForm->getUserPrice());
- }
- public function actionUserPriceTotal() {
- $userForm = new UserForm();
- $params = all_params();
- $store_id = get_store_id();
- $userForm->store_id = $store_id;
- $userForm->user_id = input_params('user_id');
- $res = $userForm->userPriceTotal($params);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'ok',
- 'data' => $res,
- ]);
- }
- public function actionGrowthSetting(){
- $store_id = get_store_id();
- if(\Yii::$app->request->isPost){
- $params = all_params();
- $res = Option::set('growth_setting', json_encode($params), $store_id, 'level');
- if($res){
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'ok',
- ]);
- }else{
- return $this->asJson([
- 'code' => 1,
- 'msg' => '保存失败',
- ]);
- }
- }else{
- $default = json_encode([
- 'buy_give' => 0,
- 'share_give' => 0,
- 'sign_give' => 0
- ]);
- $result = Option::get('growth_setting', $store_id, 'level', $default);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'ok',
- 'data' => json_decode($result['value'],true),
- ]);
- }
- }
- public function actionGrowthLog(){
- $storeId = get_store_id();
- $userId = get_params('user_id');
- $query = UserGrowthValueLog::find()->where(['user_id' => $userId,'store_id' => $storeId]);
- $list = pagination_make($query,true,'created_at DESC');
- foreach($list['list'] as &$item){
- $item['created_at'] = date('Y-m-d H:i:s',$item['created_at']);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'ok',
- 'data' => $list,
- ]);
- }
- }
|