| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130 |
- <?php
- namespace backend\controllers;
- use biz\user\services\UserOldDataService;
- use common\models\xhAdmin;
- use common\models\xhStudent;
- use Yii;
- use common\models\xhUserAlipay;
- use common\models\xhUserTag;
- use common\models\xhTrainCourse;
- use common\models\xhUser;
- use common\models\xhUserAsset;
- use common\models\xhTrainUserCourse;
- use common\services\xhUserAlipayService;
- use common\services\xhUserIntegralService;
- use common\services\xhTrainClassService;
- use common\services\xhOrderService;
- use common\services\xhPayToolService;
- use common\services\xhRechargeService;
- use common\services\xhMerchantExtendService;
- use common\services\xhMerchantAssetService;
- use common\services\xhUserAssetService;
- use common\services\xhCouponService;
- use common\services\xhUserTagService;
- use common\services\xhUserTagClassService;
- use common\services\xhAdminService;
- use common\services\xhMerchantService;
- use common\components\stringUtil;
- use common\components\weixinUtil;
- use common\components\configDict;
- use common\components\util;
- use common\components\page;
- use common\services\xhUserService;
- use common\services\xhUserByDayService;
- use common\services\xhUserUniteService;
- use common\services\xhMerchantCapitalService;
- use common\services\xhTMessageService;
- class UserController extends BackendController
- {
-
- public $sourceImg = [
- 0 => 'source_wx.jpg',
- 1 => 'source_zfb.jpg',
- 2 => 'source_xcx.jpg',
- ];
-
- /**
- * 学员导入
- * @author shish <shish@zhhinc.com>
- * @time 2019.5.12
- */
- public function actionImport()
- {
- $where = ['merchantId' => $this->merchantId];
- $page = isset($get['page']) ? $get['page'] : 1;
- $pageSize = 1000;
- $data = UserOldDataService::getListData('*', $where, $page, $pageSize, 'id desc');
- return $this->render('import', $data);
- }
-
- public function actionAll()
- {
- $get = Yii::$app->request->get();
- $query = xhUser::find();
- $query->where(['merchantId' => $this->merchantId]);
- if (isset($get['content']) && !empty($get['content'])) {
- $content = $get['content'];
- if (stringUtil::isMobieNumber($content)) {
- $query->andWhere(['mobile' => $content]);
- } else {
- $query->andWhere(['like', 'userName', $content]);
- }
- }
- if (isset($get['class']) && $get['class'] == 1) {
- $query->andWhere(['isMember' => 1]);
- }
- $countQuery = clone $query;
- $count = $countQuery->count();
- $page = isset($get['page']) ? $get['page'] : 1;
- $pageSize = 30;
- $offset = ($page - 1) * $pageSize;
- $models = $query->offset($offset)->orderBy('visitTime desc')->limit($pageSize)->asArray()->all();
- $page = new page($count, $page, $pageSize);
- $paging = $page->fpage();
- $auth = xhMerchantService::isAuth($this->merchantId);
- $merchantTag = xhUserTagClassService::getMerchantTag($this->merchantId);
- $merchantAsset = xhMerchantAssetService::getByMerchantId($this->merchantId);
- $merchantExtend = xhMerchantExtendService::getByMerchantId($this->merchantId);
- $memberIntegral = xhMerchantExtendService::getGradeList($merchantExtend, 'desc');
- return $this->render('all', [
- 'merchantTag' => $merchantTag,
- 'models' => $models,
- 'pages' => $paging,
- 'merchant' => $this->merchant,
- 'memberIntegral' => $memberIntegral,
- 'merchantAsset' => $merchantAsset,
- 'merchantExtend' => $merchantExtend,
- ]);
- }
-
- public function actionMember()
- {
- $get = Yii::$app->request->get();
- $query = xhUser::find();
- $query->where(['merchantId' => $this->merchantId]);
- if (isset($get['content']) && !empty($get['content'])) {
- $content = $get['content'];
- if (stringUtil::isMobieNumber($content)) {
- $query->andWhere(['mobile' => $content]);
- } else {
- $query->andWhere(['like', 'userName', $content]);
- }
- }
- $query->andWhere(['isMember' => 1]);
- $countQuery = clone $query;
- $count = $countQuery->count();
- $page = isset($get['page']) ? $get['page'] : 1;
- $pageSize = 20;
- $offset = ($page - 1) * $pageSize;
- $models = $query->offset($offset)->orderBy('visitTime desc')->limit($pageSize)->asArray()->all();
- $page = new page($count, $page, $pageSize);
- $paging = $page->fpage();
- $auth = xhMerchantService::isAuth($this->merchantId);
- $merchantTag = xhUserTagClassService::getMerchantTag($this->merchantId);
- $merchantAsset = xhMerchantAssetService::getByMerchantId($this->merchantId);
- $merchantExtend = xhMerchantExtendService::getByMerchantId($this->merchantId);
- $memberIntegral = xhMerchantExtendService::getGradeList($merchantExtend, 'desc');
- return $this->render('member', [
- 'merchantTag' => $merchantTag,
- 'models' => $models,
- 'pages' => $paging,
- 'merchant' => $this->merchant,
- 'memberIntegral' => $memberIntegral,
- 'merchantAsset' => $merchantAsset,
- 'merchantExtend' => $merchantExtend,
- ]);
- }
-
- public function actionFans()
- {
- $get = Yii::$app->request->get();
- $query = xhUser::find();
- $query->where(['merchantId' => $this->merchantId]);
- if (isset($get['content']) && !empty($get['content'])) {
- $content = $get['content'];
- if (stringUtil::isMobieNumber($content)) {
- $query->andWhere(['mobile' => $content]);
- } else {
- $query->andWhere(['like', 'userName', $content]);
- }
- }
- $query->andWhere(['subscribe' => 1]);
- $countQuery = clone $query;
- $count = $countQuery->count();
- $page = isset($get['page']) ? $get['page'] : 1;
- $pageSize = 20;
- $offset = ($page - 1) * $pageSize;
- $models = $query->offset($offset)->orderBy('id desc')->limit($pageSize)->asArray()->all();
- $page = new page($count, $page, $pageSize);
- $paging = $page->fpage();
- $auth = xhMerchantService::isAuth($this->merchantId);
- $merchantTag = xhUserTagClassService::getMerchantTag($this->merchantId);
- $merchantAsset = xhMerchantAssetService::getByMerchantId($this->merchantId);
- $merchantExtend = xhMerchantExtendService::getByMerchantId($this->merchantId);
- $memberIntegral = xhMerchantExtendService::getGradeList($merchantExtend, 'desc');
- return $this->render('fans', [
- 'merchantTag' => $merchantTag,
- 'models' => $models,
- 'pages' => $paging,
- 'merchant' => $this->merchant,
- 'memberIntegral' => $memberIntegral,
- 'merchantAsset' => $merchantAsset,
- 'merchantExtend' => $merchantExtend,
- ]);
- }
-
- public function actionAlipayUser()
- {
- $get = Yii::$app->request->get();
- $query = xhUserAlipay::find();
- $query->where(['merchantId' => $this->merchantId]);
- $countQuery = clone $query;
- $count = $countQuery->count();
- $page = isset($get['page']) ? $get['page'] : 1;
- $pageSize = 20;
- $offset = ($page - 1) * $pageSize;
- $models = $query->offset($offset)->orderBy('updateTime desc')->limit($pageSize)->asArray()->all();
- $page = new page($count, $page, $pageSize);
- $paging = $page->fpage();
- return $this->render('alipayUser', [
- 'models' => $models,
- 'pages' => $paging,
- ]);
- }
-
- public function actionAlipayUserDetail()
- {
- $get = Yii::$app->request->get();
- $alipayId = isset($get['alipayId']) ? $get['alipayId'] : '';
- $alipay = xhUserAlipayService::getByIds($alipayId, $this->merchantId);
- return $this->render('alipayUserDetail', ['alipay' => $alipay]);
- }
-
- public function actionDetail()
- {
- $get = Yii::$app->request->get();
- $id = isset($get['id']) ? $get['id'] : 0;
- $user = xhUserService::getById($id);
- if (empty($user) || $user['merchantId'] != $this->merchantId) {
- util::stop('非法访问');
- }
- $userAsset = xhUserAssetService::getByUserId($id);
- //已经查看了此用户,将用户从呼叫列表删除
- Yii::$app->redis->executeCommand('ZREM', ["merchant_{$this->merchantId}_new_call", "{$id}"]);
- $class = xhTrainClassService::getAllByCondition(['merchantId' => $this->merchantId]);
- //取商标的所有用户标签
- $merchantTag = xhUserTagClassService::getMerchantTag($this->merchantId);
- $userTag = xhUserTagService::getUserTag($id);
- $coupon = xhCouponService::getUserCoupon($id);//取代金劵
- $merchantExtend = xhMerchantExtendService::getByMerchantId($this->merchantId);
- $memberIntegral = xhMerchantExtendService::getGradeList($merchantExtend, 'desc');
- $freight = configDict::getConfig('freight');//运费计算
- $alipayId = 0;
- $alipayInfo = [];
- if (!empty($user['alipayId'])) {
- $alipayId = $user['alipayId'];
- $alipayInfo = xhUserAlipayService::getByIds($alipayId, $this->merchantId);
- }
- return $this->render('detail', [
- 'merchantExtend' => $merchantExtend,
- 'userTag' => $userTag,
- 'coupon' => $coupon,
- 'merchantTag' => $merchantTag,
- 'class' => $class,
- 'user' => $user,
- 'userAsset' => $userAsset,
- 'memberIntegral' => $memberIntegral,
- 'freight' => $freight,
- 'merchant' => $this->merchant,
- 'alipayInfo' => $alipayInfo,
- ]);
- }
-
- /**
- * 升级为会员
- */
- public function actionUpgrade()
- {
- $get = Yii::$app->request->get();
- $adminId = $this->adminId;
- $admin = xhAdminService::getById($adminId);
- if (isset($get['confirmPassword']) == false) {
- util::failInfo('请填写确认密码');
- }
- if (isset($get['memberLevel']) == false || empty($get['memberLevel'])) {
- util::failInfo('请选择等级数');
- }
- $userId = isset($get['userId']) ? $get['userId'] : 0;
- $memberLevel = $get['memberLevel'];
- $user = xhUserService::getById($userId);
- if (empty($user) || $user['merchantId'] != $this->merchantId) {
- util::failInfo('客户不存在');
- }
- if (empty($user['mobile'])) {
- util::failInfo('客户还没有绑定手机号');
- }
- $mobile = $user['mobile'];
- $oldData = UserOldDataService::getByCondition(['merchantId' => $this->merchantId, 'mobile' => $mobile]);
- if (!empty($oldData)) {
- util::failInfo('这个客人有老客户记录,无法手动升级');
- }
-
- $confirmPassword = $get['confirmPassword'];
- if (md5($confirmPassword) != $admin['confirmPassword']) {
- util::failInfo('确认密码有误');
- }
- $grade = xhMerchantExtendService::getGradeList($this->merchantExtend, 'desc');
- $newLevelPoint = $grade[$memberLevel]['integral'];//升级到当前级别需要的积分数
- $userAsset = xhUserAssetService::getByUserId($userId);//用户资产
- if (!empty($userAsset['isMember']) && $userAsset['memberLevel'] >= $memberLevel) {
- util::failInfo('客户已经达到此级别了');
- }
-
- $connection = Yii::$app->db;//事务处理
- $transaction = $connection->beginTransaction();
- try {
-
- $addPoint = $newLevelPoint - $userAsset['integral'];
- $upData['integral'] = $newLevelPoint;//升级后的积分
- $upData['memberLevel'] = $memberLevel;
- $upData['isMember'] = 1;
- xhUserAssetService::updateByUserId($userId, $upData);
-
- $old = ['mobile' => $mobile, 'merchantId' => $this->merchantId, 'createTime' => date("Y-m-d H:i:s"), 'integral' => $addPoint, 'status' => 1];
- $return = UserOldDataService::add($old);
- if (empty($return)) {
- util::failInfo('升级失败');
- }
- $targetId = $return['id'];
- $now = time();
- $date = date("Y-m-d H:i", $now);
-
- $integralData = [
- 'userId' => $userId,
- 'userName' => $user['userName'],
- 'merchantId' => $this->merchantId,
- 'relateId' => (string)$targetId,
- 'integral' => $newLevelPoint,
- 'num' => $addPoint,
- 'io' => 1,
- 'payWay' => 4,
- 'alipayId' => '',
- 'event' => '店长操作升级',
- 'operatorId' => $userId,
- 'createTime' => $date,
- 'capitalType' => 0,
- 'addTime' => $now,
- ];
- xhUserIntegralService::add($integralData);//用户兑换型积分流水增加
- $transaction->commit();
- } catch (Exception $e) {
- $transaction->rollBack();
- util::failInfo();
- }
-
- $allTM = xhTMessageService::getList($this->merchantId);
- $openId = $user['openId'];
- $shortTempId = 'OPENTM205211943';//升级通知
- if (isset($allTM[$shortTempId])) {
- $tempId = $allTM[$shortTempId];
- $data = [
- "touser" => $openId, "template_id" => $tempId, "url" => '',
- "data" => [
- "first" => ["value" => "恭喜,您已经升为{$memberLevel}级会员。", "color" => "#173177"],
- "keyword1" => ["value" => $user['userName'], "color" => "#173177"],
- "keyword2" => ["value" => $date, "color" => "#173177"],
- "remark" => ["value" => "点击查看会员权益", "color" => "#173177"],
- ]];
- weixinUtil::sendTaskInform($data, $this->merchant);
- }
- util::successInfo();
- }
-
- /**
- * 充值
- */
- public function actionRecharge()
- {
- $get = Yii::$app->request->get();
- $rechargePassword = isset($get['rechargePassword']) ? $get['rechargePassword'] : '';
- $adminId = $this->adminId;
- $admin = xhAdminService::getById($adminId);
- if (empty($admin['confirmPassword'])) {
- util::failInfo('您还没有设置确认密码');
- }
- if (md5($rechargePassword) != $admin['confirmPassword']) {
- util::failInfo('确认密码有误哦');
- }
- $userId = isset($get['userId']) ? $get['userId'] : 0;
- $rechargeAmount = isset($get['rechargeAmount']) ? $get['rechargeAmount'] : 1;
- $user = xhUserService::getById($userId);
- if (empty($user) || $user['merchantId'] != $this->merchantId) {
- util::failInfo('访问出错,请联系网站管理员');
- }
- $userAsset = xhUserAssetService::getByUserId($userId);
- if (empty($userAsset)) {
- util::failInfo('操作出错,请与网站管理员联系');
- }
- $totalBalance = $userAsset['balance'] + $rechargeAmount;
- $totalRecharge = $userAsset['totalRecharge'] + $rechargeAmount;
- $upData['balance'] = $totalBalance;
- $upData['totalRecharge'] = $totalRecharge;
- $return = xhRechargeService::recharge($rechargeAmount, $user, $this->adminId, $this->merchant, $this->merchantExtend, $this->merchantAsset);
- if ($return['code'] == 'A0001') {
- util::successInfo('充值成功');
- }
- util::successInfo('充值失败');
- }
-
- /**
- * 现金支付,转店主微信,转店主支付宝
- */
- public function actionCashPay()
- {
- $post = Yii::$app->request->post();
- $extend = $this->merchantExtend;
- //dump($post);die;
- $getUid = Yii::$app->request->get('userId');
- $userId = isset($getUid) ? $getUid : 0;
- $amount = isset($post['consumeAmount']) ? $post['consumeAmount'] : 1;
- $couponId = isset($post['couponId']) ? $post['couponId'] : 1;
-
- $user = xhUserService::getById($userId, $this->merchantId);
- /*if($user['merchantId'] != $this->merchantId){
- util::failInfo('非法访问');
- }*/
- if (!empty($user) && empty($user['subscribe'])) {
- util::failInfo('客户要关注公众号才能结算');
- }
- /*if(!empty($couponId)){
- $coupon = xhCouponService::getById($couponId);
- if($coupon['merchantId'] != $this->merchantId){
- util::failInfo('非法代金劵');
- }
- if($coupon['useStatus'] == 1 || time() > $coupon['deadline']){
- util::failInfo('代金劵已经失效');
- }
- if($coupon['meetAmount'] > $amount){
- util::failInfo('消费不足'.$coupon['meetAmount'].'元');
- }
- }*/
-
- $payWay = configDict::getConfig('payWay', 'cashPay');
- $payStyle = configDict::getConfig('payStyle', 'cashPay');
- $now = time();
- $expireTime = $now + 300;//订单5分钟后过期
- $payAdd['prePrice'] = $amount;
- $payAdd['actPrice'] = $amount;
- $payAdd['payWay'] = $payWay;
- $payAdd['payStyle'] = $payStyle;
- $payAdd['payStatus'] = 0;
- $payAdd['userId'] = $userId;
- $payAdd['merchantId'] = $this->merchantId;
- $payAdd['createTime'] = date("Y-m-d H:i:s", $now);
- $payAdd['deadline'] = $expireTime;
- xhOrderService::formatPost($payAdd, $post);
- $order = xhOrderService::add($payAdd);
- $id = $order['id'];
-
- $typeList = configDict::getConfig('capitalType');
- $capitalType = $typeList['xhOrder']['id'];
- $return = xhPayToolService::cashPay($id, $amount, $capitalType, $couponId);
-
- if ($return['code'] == 'A0001') {
- util::successInfo('登记成功');
- } else {
- Yii::warning(json_encode($return));
- }
- util::failInfo('登记没有成功');
- }
-
- /**
- * 重置支付密码
- */
- public function actionResetPayPassword()
- {
- $get = Yii::$app->request->get();
- $id = isset($get['id']) ? $get['id'] : 0;
- $user = xhUserService::getById($id);
- if (empty($user) || $user['merchantId'] != $this->merchantId) {
- util::failInfo('没有这个客户');
- }
- if (empty($user['subscribe'])) {
- util::failInfo('客户要先关注公众号哦');
- }
- $rand = stringUtil::getRandNum(6);
- xhUserService::updateById($id, ['payPassword' => md5($rand)]);
- $openId = $user['openId'];
- $allTM = xhTMessageService::getList($this->merchantId);
- $shortTempId = 'OPENTM207430125';
- if (isset($allTM[$shortTempId])) {
- $tempId = $allTM[$shortTempId];
- $url = Yii::$app->params['frontUrl'] . '/center/password?account=' . $this->merchant['id'];
- $data = [
- "touser" => $openId, "template_id" => $tempId, "url" => $url,
- "data" => ["first" => ["value" => '操作成功', "color" => "#173177"],
- "keyword1" => ["value" => "你的支付密码已经重置为:" . $rand, "color" => "#173177"],
- "keyword2" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
- "remark" => ["value" => "点此修改成好记的密码哦", "color" => "#173177"]]];
- weixinUtil::sendTaskInform($data, $this->merchant);
- }
- util::successInfo();
- }
-
- /**
- * 导出用户,备份用户
- */
- public function actionExport()
- {
- $query = xhUserAsset::find();
- $query->where(['merchantId' => $this->merchantId])->andWhere(['>', 'integral', 0]);
- $userAsset = $query->orderBy('integral desc')->all();
- if (empty($userAsset)) {
- echo '没有获得积分用户';
- Yii::$app->end();
- }
- $objectPHPExcel = new \PHPExcel();
- $objectPHPExcel->setActiveSheetIndex(0);
-
- $memberCount = xhUserAsset::find()->andWhere(['isMember' => 1, 'merchantId' => $this->merchantId])->count('id');//会员数
- $allUsercount = xhUserAsset::find()->andWhere(['merchantId' => $this->merchantId])->count('id');//用户数
-
- //报表头的输出
- $objectPHPExcel->getActiveSheet()->mergeCells('B1:G1');
- $objectPHPExcel->getActiveSheet()->setCellValue('B1', '用户信息表');
-
- $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('B2', '用户信息表');
- $objectPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getFont()->setSize(24);
- $objectPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
-
- $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('B2', '日期:' . date("Y年m月j日"));
- $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('F2', '用户数:' . $allUsercount);
- $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('G2', '会员数:' . $memberCount);
- $objectPHPExcel->setActiveSheetIndex(0)->getStyle('F2')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);//右居中
- $objectPHPExcel->setActiveSheetIndex(0)->getStyle('G2')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);//右居中
-
- //表格头的输出
- $objectPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(5);
- $objectPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(7);
- $objectPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
- $objectPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(17);
- $objectPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
- $objectPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
- $objectPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(22);
- $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('B3', '编号');
- $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('C3', '昵称');
- $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('D3', '会员等级');
- $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('E3', '余额');
- $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('F3', '积分');
- $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('G3', '创建日期');
-
- //设置居中
- $objectPHPExcel->getActiveSheet()->getStyle('B3:G3')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
-
- //设置边框
- $objectPHPExcel->getActiveSheet()->getStyle('B3:G3')->getBorders()->getTop()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
- $objectPHPExcel->getActiveSheet()->getStyle('B3:G3')->getBorders()->getLeft()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
- $objectPHPExcel->getActiveSheet()->getStyle('B3:G3')->getBorders()->getRight()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
- $objectPHPExcel->getActiveSheet()->getStyle('B3:G3')->getBorders()->getBottom()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
- $objectPHPExcel->getActiveSheet()->getStyle('B3:G3')->getBorders()->getVertical()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
-
- //设置颜色
- $objectPHPExcel->getActiveSheet()->getStyle('B3:G3')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF66CCCC');
-
- foreach ($userAsset as $subKey => $subMUser) {
- //明细的输出
- $objectPHPExcel->getActiveSheet()->setCellValue('B' . ($subKey + 4), $subKey + 1);
- $objectPHPExcel->getActiveSheet()->setCellValue('C' . ($subKey + 4), $subMUser->xhUser->userName);
- $objectPHPExcel->getActiveSheet()->setCellValue('D' . ($subKey + 4), $subMUser->memberLevel);
- $objectPHPExcel->getActiveSheet()->setCellValue('E' . ($subKey + 4), $subMUser->balance);
- $objectPHPExcel->getActiveSheet()->setCellValue('F' . ($subKey + 4), $subMUser->integral);
- $objectPHPExcel->getActiveSheet()->setCellValue('G' . ($subKey + 4), $subMUser->createTime);
- //设置边框
- $currentRowNum = $subKey + 4;
- $objectPHPExcel->getActiveSheet()->getStyle('B' . ($subKey + 4) . ':G' . $currentRowNum)->getBorders()->getTop()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
- $objectPHPExcel->getActiveSheet()->getStyle('B' . ($subKey + 4) . ':G' . $currentRowNum)->getBorders()->getLeft()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
- $objectPHPExcel->getActiveSheet()->getStyle('B' . ($subKey + 4) . ':G' . $currentRowNum)->getBorders()->getRight()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
- $objectPHPExcel->getActiveSheet()->getStyle('B' . ($subKey + 4) . ':G' . $currentRowNum)->getBorders()->getBottom()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
- $objectPHPExcel->getActiveSheet()->getStyle('B' . ($subKey + 4) . ':G' . $currentRowNum)->getBorders()->getVertical()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
- }
-
- //设置分页显示
- //$objectPHPExcel->getActiveSheet()->setBreak( 'I55' , \PHPExcel_Worksheet::BREAK_ROW );
- //$objectPHPExcel->getActiveSheet()->setBreak( 'I10' , \PHPExcel_Worksheet::BREAK_COLUMN );
- $objectPHPExcel->getActiveSheet()->getPageSetup()->setHorizontalCentered(true);
- $objectPHPExcel->getActiveSheet()->getPageSetup()->setVerticalCentered(false);
-
- ob_end_clean();
- ob_start();
-
- header('Content-Type : application/vnd.ms-excel');
- header('Content-Disposition:attachment;filename="' . $this->merchant['merchantName'] . '会员' . date("Ymj") . '.xls"');
- $objWriter = \PHPExcel_IOFactory::createWriter($objectPHPExcel, 'Excel5');
- $objWriter->save('php://output');
- }
-
- /**
- * 报名培训
- */
- public function actionApplyTrain()
- {
- $get = Yii::$app->request->get();
- $userId = $get['userId'];
- $user = xhUserService::getById($userId);
- if (empty($user) || $user['merchantId'] != $this->merchantId) {
- util::failInfo('学员不存在');
- }
- if (empty($user['subscribe'])) {
- util::failInfo('学员还没有关注公众号哦~');
- }
- $student = xhStudent::getByCondition(['userId' => $userId, 'merchantId' => $this->merchantId]);
- if (!empty($student)) {
- util::failInfo('已经报过名了哦~');
- }
- $classId = isset($get['classId']) ? $get['classId'] : 0;
- $class = xhTrainClassService::getById($classId);
- if (empty($class)) {
- util::failInfo('课程不存在哦~');
- }
- $nowTime = time();
- $stuData = ['userId' => $userId, 'merchantId' => $this->merchantId, 'registerTime' => $nowTime, 'classId' => $class['id'],
- 'addTime' => $nowTime, 'modTime' => $nowTime, 'tuition' => $class['tuition'], 'className' => $class['name'], 'lesson' => $class['lesson']];
- $student = xhStudent::add($stuData);
- $course = xhTrainCourse::getAllByCondition(['classId' => $classId]);
- $userCourse = [];
- foreach ($course as $key => $val) {
- $userCourse[] = ['courseId' => $val['id'], 'courseName' => $val['name'], 'courseIntro' => $val['intro'], 'classId' => $classId, 'studentId' => $student['id'], 'userId' => $userId, 'merchantId' => $this->merchantId];
- }
- xhTrainUserCourse::batchAdd($userCourse);
- xhUserService::updateById($userId, ['identity' => 1]);
-
- $allTM = xhTMessageService::getList($this->merchantId);
- $openId = $user['openId'];
- $shortTempId = 'OPENTM401027382';
- if (isset($allTM[$shortTempId])) {
- $tempId = $allTM[$shortTempId];
- $data = array(
- "touser" => $openId,
- "template_id" => $tempId,//模板id,从公众平台后台取得
- "url" => $this->frontUrl . '/center/student-card?account=' . $this->merchant['id'],
- "data" => array(
- "first" => array(
- "value" => "恭喜,您已经成功报名。",
- "color" => "#173177"
- ),
- "keyword1" => array(
- "value" => $class['name'],
- "color" => "#173177"
- ),
- "keyword2" => array(
- "value" => date("Y-m-d H:i"),
- "color" => "#173177"
- ),
- "remark" => array(
- "value" => "您的学员卡已经激活,点此查看课程内容",
- "color" => "#173177"
- ),
- ),
- );
- }
- weixinUtil::sendTaskInform($data, $this->merchant);
- util::successInfo('报名成功~');
- }
-
- public function actionRemark()
- {
- $get = Yii::$app->request->get();
- $userId = isset($get['userId']) ? $get['userId'] : 0;
- $user = xhUserService::getById($userId);
- if (empty($user) || $user['merchantId'] != $this->merchantId) {
- util::failInfo('用户不存在');
- }
- $remark = isset($get['remark']) ? $get['remark'] : '';
- xhUserService::updateById($userId, ['remark' => $remark]);
- util::successInfo();
- }
-
- public function actionTagUserList()
- {
- $get = Yii::$app->request->get();
- $tagId = isset($get['tagId']) ? $get['tagId'] : 0;
- $tagInfo = xhUserTagClassService::getByCondition(['tagId' => $tagId]);
- if (empty($tagInfo) || $tagInfo['merchantId'] != $this->merchantId) {
- util::stop('不合法标签');
- }
- $query = xhUserTag::find();
- $query->where(['tagId' => $tagId]);
- $query->orderBy('id desc');
- $countQuery = clone $query;
- $count = $countQuery->count();
- $page = isset($get['page']) ? $get['page'] : 1;
- $pageSize = 20;
- $offset = ($page - 1) * $pageSize;
- $models = $query->offset($offset)->orderBy('id desc')->limit($pageSize)->asArray()->all();
- $page = new page($count, $page, $pageSize);
- $paging = $page->fpage();
- $merchantTag = xhUserTagClassService::getMerchantTag($this->merchantId);
- return $this->render('tagUserList', ['models' => $models, 'paging' => $paging, 'merchantTag' => $merchantTag, 'tagInfo' => $tagInfo]);
- }
-
- public function actionTag()
- {
- $tag = xhUserTagClassService::getAllByCondition(['merchantId' => $this->merchantId]);
- return $this->render('tag', ['tag' => $tag]);
- }
-
- /**
- * 添加用户标签
- */
- public function actionTagAdd()
- {
- $post = Yii::$app->request->post();
- if (isset($post['tagName']) == false || empty($post['tagName'])) {
- util::failInfo('请填写标签名称');
- }
- $name = $post['tagName'];
- $tagArr = xhUserTagClassService::getMerchantTag($this->merchantId);
- if (!empty($tagArr) && in_array($name, $tagArr)) {
- util::failInfo('标签已经存在了');
- }
- $return = weixinUtil::createTag($this->merchant, $name);
- if (isset($return['errcode']) == false) {
- $tagId = $return['tag']['id'];
- $data = ['tagId' => $tagId, 'name' => $name, 'merchantId' => $this->merchantId];
- xhUserTagClassService::add($data, $this->merchantId);
- util::successInfo();
- }
- $errCode = $return['errcode'];
- $errList = weixinUtil::$errCodes;
- $msg = $errList[$errCode];
- util::failInfo($msg);
- }
-
- /**
- * 删除用户标签
- */
- public function actionTagDel()
- {
- $get = Yii::$app->request->get();
- if (isset($get['tagId']) == false || empty($get['tagId'])) {
- util::failInfo('请选择你要删除的标签');
- }
- $tagId = $get['tagId'];
- $status = xhUserTagService::getUserByTagId($tagId);
- if ($status) {
- util::failInfo('标签下还有用户,无法删除');
- }
- $tag = xhUserTagClassService::getByCondition(['tagId' => $tagId, 'merchantId' => $this->merchantId]);
- if (empty($tag)) {
- util::failInfo('标签不存在');
- }
- if ($tag['merchantId'] != $this->merchantId) {
- util::failInfo('非法操作');
- }
- $wxTagId = $tag['tagId'];
- $return = weixinUtil::delTag($this->merchant, $wxTagId);
- if (isset($return['errcode']) && $return['errcode'] == 0) {
- xhUserTagClassService::deleteByCondition(['tagId' => $tagId, 'merchantId' => $this->merchantId], $this->merchantId);
- util::successInfo();
- }
- $errCode = $return['errcode'];
- $errList = weixinUtil::$errCodes;
- $msg = $errList[$errCode];
- util::failInfo($msg);
- }
-
- /**
- * 修改标签
- */
- public function actionTagMod()
- {
- $get = Yii::$app->request->get();
- if (isset($get['id']) == false || empty($get['id'])) {
- util::failInfo('请选择标签');
- }
- $id = $get['id'];
- $tag = xhUserTagClassService::getByCondition(['id' => $id]);
- if (empty($tag)) {
- util::failInfo('标签已删除');
- }
- if ($tag['merchantId'] != $this->merchantId) {
- util::failInfo('非法访问');
- }
- $tagId = $tag['tagId'];
- $name = $get['tagName'];
- $return = weixinUtil::modTag($this->merchant, $tagId, $name);
- if (isset($return['errcode']) && $return['errcode'] == 0) {
- $data = ['name' => $name];
- xhUserTagClassService::updateById($id, $data, $this->merchantId);
- util::successInfo('操作成功');
- }
- $errCode = $return['errcode'];
- $errList = weixinUtil::$errCodes;
- $msg = $errList[$errCode];
- util::failInfo($msg);
- }
-
- /**
- * 对每个用户设置标签
- */
- public function actionTagSet()
- {
- $get = Yii::$app->request->get();
- $userId = isset($get['userId']) ? $get['userId'] : 0;
- $user = xhUserService::getById($userId);
- if (empty($user) || $user['merchantId'] != $this->merchantId) {
- util::failInfo('非法用户');
- }
- $tagId = isset($get['tagId']) ? $get['tagId'] : '';
- $merchantTag = xhUserTagClassService::getMerchantTag($this->merchantId);
- $mTag = array_flip($merchantTag);
- //防止非法标签id
- if (in_array($tagId, $mTag) == false) {
- util::failInfo('非法标签');
- }
- $userTag = xhUserTagService::getUserTag($userId);
- if (count($userTag) >= 3) {
- util::failInfo('最多只能设置三个标签哦');
- }
- if (in_array($tagId, $userTag)) {
- util::failInfo('此标签已经添加过了');
- }
- $openIdList = [$user['openId']];
- $return = weixinUtil::membersBatchTag($this->merchant, $openIdList, $tagId);
- if (isset($return['errcode']) == false) {
- util::failInfo('操作未成功,微信服务器没有返回');
- }
- if ($return['errcode'] != 0) {
- $errCode = $return['errcode'];
- $errList = weixinUtil::$errCodes;
- $msg = isset($errList[$errCode]) ? $errList[$errCode] : '';
- util::failInfo($msg);
- }
- $addTagData = ['merchantId' => $this->merchantId, 'tagId' => $tagId, 'userId' => $userId];
- xhUserTagService::add($addTagData);
- util::successInfo();
- }
-
- /**
- * 删除用户的标签
- */
- public function actionTagRemove()
- {
- $get = Yii::$app->request->get();
- $userId = isset($get['userId']) ? $get['userId'] : 0;
- $user = xhUserService::getById($userId);
- if (empty($user) || $user['merchantId'] != $this->merchantId) {
- util::failInfo('非法用户');
- }
- $tagId = isset($get['tagId']) ? $get['tagId'] : '';
- $merchantTag = xhUserTagClassService::getMerchantTag($this->merchantId);
- $mTag = array_flip($merchantTag);
- //防止非法标签id
- if (in_array($tagId, $mTag) == false) {
- util::failInfo('非法标签');
- }
- $openIdList = [$user['openId']];
- $return = weixinUtil::membersCancelTag($this->merchant, $openIdList, $tagId);
- if (isset($return['errcode']) == false) {
- util::failInfo('操作未成功,微信服务器没有返回');
- }
- if ($return['errcode'] != 0) {
- $errCode = $return['errcode'];
- $errList = weixinUtil::$errCodes;
- $msg = isset($errList[$errCode]) ? $errList[$errCode] : '';
- util::failInfo($msg);
- }
- xhUserTagService::deleteByCondition(['tagId' => $tagId, 'merchantId' => $this->merchantId, 'userId' => $userId]);
- util::successInfo('操作成功');
- }
-
- /**
- * 给多个用户添加标签
- */
- public function actionBatchAddUserTag()
- {
- $get = Yii::$app->request->get();
- if (isset($get['tagId']) == false || empty($get['tagId'])) {
- util::failInfo('请选择标签');
- }
- if (isset($get['userIdStr']) == false || empty($get['userIdStr'])) {
- util::failInfo('请选择用户');
- }
- $tagId = $get['tagId'];
- $userIdStr = trim($get['userIdStr']);
- $userIdList = explode(',', $userIdStr);
- $userIds = xhUserTagService::getUserIdByTagId($tagId, $this->merchantId);//取标签下的用户
- $toDoIds = array_diff($userIdList, $userIds);
- if (empty($toDoIds)) {
- util::successInfo('全部用户已经设置此标签了~');
- }
- $openIdList = [];
- $toSaveData = [];
- foreach ($toDoIds as $doKey => $doUserId) {
- $userInfo = xhUserService::getById($doUserId);
- if ($userInfo['merchantId'] == $this->merchantId) {
- $openIdList[] = $userInfo['openId'];
- $toSaveData[] = ['merchantId' => $this->merchantId, 'tagId' => $tagId, 'userId' => $doUserId];
- }
- }
- $return = weixinUtil::membersBatchTag($this->merchant, $openIdList, $tagId);//批量为用户打标签
- if (isset($return['errcode']) == false) {
- util::failInfo('操作失败');
- }
- if ($return['errcode'] == 0) {
- xhUserTagService::batchAdd($toSaveData);
- util::successInfo('操作成功');
- }
- $errCode = $return['errcode'];
- $errList = weixinUtil::$errCodes;
- $msg = isset($errList[$errCode]) ? $errList[$errCode] : '操作失败';
- util::failInfo($msg);
- }
-
- /**
- * 发放代金劵
- */
- public function actionGrantCoupon()
- {
- $get = Yii::$app->request->get();
- $userId = isset($get['userId']) ? $get['userId'] : 0;
- $userInfo = xhUserService::getById($userId);
- $merchantId = isset($userInfo['merchantId']) ? $userInfo['merchantId'] : 0;
- if ($this->merchantId != $merchantId) {
- util::failInfo('不是你的用户');
- }
- $duration = isset($get['duration']) && !empty($get['duration']) ? $get['duration'] : 60;
- $amount = isset($get['amount']) && !empty($get['amount']) ? $get['amount'] : 5;
- $meetAmount = isset($get['meetAmount']) && !empty($get['meetAmount']) ? $get['meetAmount'] : 150;
- if ($meetAmount <= $amount) {
- util::failInfo('消费金额要大于代金劵金额');
- }
- $get['beginTime'] = isset($get['beginTime']) && !empty($get['beginTime']) ? strtotime($get['beginTime']) : time();
- $get['deadline'] = $get['beginTime'] + $duration * 86400;
- $get['amount'] = $amount;
- $get['meetAmount'] = $meetAmount;
- $get['createTime'] = date("Y-m-d H:i:s");
- $get['merchantId'] = $this->merchantId;
- $get['userId'] = $userId;
- $get['number'] = 'CO' . stringUtil::buildOrderNo($userId);//代金劵编号
- xhCouponService::add($get, $userId);
- $allTM = xhTMessageService::getList($this->merchantId);
- $shortTempId = 'OPENTM207112032';//收入提醒
- if (isset($allTM[$shortTempId])) {
- $tempId = $allTM[$shortTempId];
- $openId = $userInfo['openId'];
- $data = ["touser" => $openId, "template_id" => $tempId,
- "url" => $this->frontUrl . '/center/coupon?account=' . $this->merchant['id'],
- "data" => [
- "first" => ["value" => "亲,您获得一张代金劵哦。", "color" => "#173177"],
- "keyword1" => ["value" => '代金劵', "color" => "#173177"],
- "keyword2" => ["value" => $amount . '元', "color" => "#173177"],
- "keyword3" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
- "remark" => ["value" => "点击查看详情", "color" => "#173177"]]];
- weixinUtil::sendTaskInform($data, $this->merchant);
- }
- util::successInfo();
- }
-
- public function actionTrend()
- {
- $fans = xhUserByDayService::getLatestNum($this->merchantId, 29);
- return $this->render('trend', ['fans' => $fans,]);
- }
-
- /**
- * 将支付宝关联上微信号,积分迁移到微信号上
- */
- public function actionRelateUser()
- {
- $get = Yii::$app->request->get();
- $userId = isset($get['userId']) ? $get['userId'] : 0;
- $alipayId = isset($get['alipayId']) ? $get['alipayId'] : 0;
- $relation = xhUserAlipayService::getByIds($alipayId, $this->merchantId);
- if (empty($relation)) {
- util::failInfo('消费信息不存在');
- }
- if (isset($relation['userId']) && !empty($relation['userId'])) {
- util::failInfo('帐号已经绑定过了');
- }
- $user = xhUserService::getById($userId);
- if ($user['merchantId'] != $this->merchantId) {
- util::failInfo('不是您的用户');
- }
- $openId = $user['openId'];
- $userName = $user['userName'];
- if (!empty($user['alipayId'])) {
- util::failInfo($userName . '已经绑定过支付宝了');
- }
- xhUserAlipayService::updateByIds($alipayId, $this->merchantId, ['openId' => $openId, 'userId' => $userId, 'status' => 1]);
- $merchant = $this->merchant;
- $merchantExtend = $this->merchantExtend;
- $merchantId = $this->merchantId;
- $date = date("Y-m-d H:i:s");
- $now = time();
- $userAsset = xhUserAssetService::getByUserId($userId);
- $capitalTypeList = configDict::getConfig('capitalType');
- $capitalType = $capitalTypeList['xhUserUnite']['id'];
- $point = $relation['point'];
- $addIntegral = $point;
- $addPoint = $point;
- $totalExpend = $relation['totalExpend'];
- $uniteData = [
- 'alipayId' => $alipayId,
- 'merchantId' => $this->merchantId,
- 'userId' => $userId,
- 'point' => $point,
- 'totalExpend' => $totalExpend,
- 'operateId' => $this->adminId,
- 'addTime' => time(),
- 'createTime' => $date,
- ];
- $order = xhUserUniteService::add($uniteData);
- $orderId = $order['id'];
- $payWay = configDict::getConfig('payWay', 'alipay');
- $userIntegral = stringUtil::calcAdd($userAsset['integral'], $point);
- $userPoint = stringUtil::calcAdd($userAsset['point'], $point);
- $totalExpend = stringUtil::calcAdd($userAsset['totalExpend'], $totalExpend);
- $upAssetData = [];
- $upAssetData['integral'] = $userIntegral;
- $upAssetData['point'] = $userPoint;
- $upAssetData['totalExpend'] = $totalExpend;
- xhUserAssetService::ioChangeAsset($user, $userAsset, $upAssetData, $merchant, $merchantExtend, $order, $capitalType);//用户资产改变
-
- xhUserService::updateById($userId, ['alipayId' => $alipayId]);
-
- $integralData = [
- 'userId' => $userId,
- 'userName' => $userName,
- 'merchantId' => $merchantId,
- 'relateId' => (string)$orderId,
- 'integral' => $userIntegral,
- 'num' => $addIntegral,
- 'io' => 1,
- 'payWay' => $payWay,
- 'alipayId' => $alipayId,
- 'event' => '绑定支付宝帐号获得积分',
- 'operatorId' => $userId,
- 'createTime' => $date,
- 'addTime' => $now,
- 'capitalType' => $capitalType,
- ];
- xhUserIntegralService::add($integralData);//用户兑换型积分流水增加
-
- xhMerchantCapitalService::updateByCondition(['alipayId' => $alipayId, 'merchantId' => $this->merchantId], ['userId' => $userId, 'userName' => $userName]);
- xhOrderService::updateByCondition(['alipayId' => $alipayId, 'merchantId' => $this->merchantId], ['userId' => $userId]);
- util::successInfo();
- }
-
- /**
- * 关联前获取用户信息
- */
- public function actionGetUser()
- {
- $get = Yii::$app->request->get();
- $id = isset($get['id']) ? $get['id'] : 0;
- $user = xhUserService::getById($id);
- if ($user['subscribe'] == 0) {
- util::failInfo('没有关注公众号');
- }
- if ($user['merchantId'] != $this->merchantId) {
- util::failInfo('非法操作');
- }
- $largeImg = $user['avatar'];
- $avatarList = xhUserService::getAvatarList($largeImg);
- $avatar = $avatarList['small'];
- util::successInfo('操作成功', 'A0001', ['id' => $id, 'avatar' => $avatar, 'userName' => $user['userName']]);
- }
-
- public function actionStudent()
- {
- $get = Yii::$app->request->get();
- $query = xhStudent::find();
- $countQuery = clone $query;
- $count = $countQuery->count();
- $page = isset($get['page']) ? $get['page'] : 1;
- $pageSize = 20;
- $offset = ($page - 1) * $pageSize;
- $models = $query->offset($offset)->with('xhUser')->orderBy('visitTime desc')->limit($pageSize)->all();
- $page = new page($count, $page, $pageSize);
- $paging = $page->fpage();
- return $this->render('student', [
- 'models' => $models,
- 'pages' => $paging,
- ]);
- }
-
- public function actionLevel()
- {
- $extend = xhMerchantExtendService::getByMerchantId($this->merchantId);
- $gradeList = xhMerchantExtendService::getGradeList($extend);
- return $this->render('level', ['extend' => $extend, 'gradeList' => $gradeList]);
- }
-
- /**
- * 导入老客户
- */
- public function actionImportOldUser()
- {
- $request = Yii::$app->request->get();
- $mobile = $request['mobile'];
- $integral = $request['integral'];
- $balance = $request['balance'];
- $userName = isset($request['userName']) && !empty($request['userName']) ? $request['userName'] : $mobile;
- $confirmPassword = $request['confirmPassword'];
- $confirmMobile = $request['confirmMobile'];
- if ($mobile != $confirmMobile) {
- util::failInfo('二次手机号不致');
- }
- if (stringUtil::isMobieNumber($mobile) == false) {
- util::failInfo('手机号填写错误');
- }
- $adminId = $this->adminId;
- $admin = xhAdminService::getById($adminId);
- $confirmPassword = $request['confirmPassword'];
- if (md5($confirmPassword) != $admin['confirmPassword']) {
- util::failInfo('确认密码有误');
- }
- if ($integral == $balance && $balance == 0) {
- util::failInfo('请填写积分或余额');
- }
- $return = UserOldDataService::couldAdd($this->merchantId, $mobile);
- if ($return['status'] == false) {
- util::failInfo($return['msg']);
- }
- $integral = isset($integral) && $integral > 0 ? $integral : 0;
- $balance = isset($balance) && $balance > 0 ? $balance : 0;
- $data = ['mobile' => $mobile, 'integral' => $integral, 'balance' => $balance, 'createTime' => date("Y-m-d H:i:s"), 'userName' => $userName, 'merchantId' => $this->merchantId];
- UserOldDataService::add($data);
- util::successInfo();
- }
-
- public function actionBindMobile()
- {
- $userId = Yii::$app->request->get('userId');
- $mobile = Yii::$app->request->get('mobile');
- $info = xhUserService::getById($userId);
- if ($info['merchantId'] != $this->merchantId) {
- util::failInfo();
- }
- if ($info['subscribe'] != 1) {
- util::failInfo('客户还没有关注公众号,无法绑定手机号');
- }
- if (!empty($info['mobile'])) {
- util::failInfo('您已经有绑定手机号了');
- }
- $status = xhUserService::mobileNotUsed($mobile, $this->merchantId);
- if ($status == false) {
- util::failInfo('手机号已经被使用');
- }
- xhUserService::updateById($userId, ['mobile' => $mobile, 'isMember' => 1]);
- xhUserAssetService::updateByUserId($userId, ['isMember' => 1]);
- //绑定手机时判断是否有老客户资料
- UserOldDataService::import($this->merchantId, $userId, $mobile);
- util::successInfo('操作成功');
- }
-
- }
|