UserController.php 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  1. <?php
  2. namespace backend\controllers;
  3. use biz\user\services\UserOldDataService;
  4. use common\models\xhAdmin;
  5. use common\models\xhStudent;
  6. use Yii;
  7. use common\models\xhUserAlipay;
  8. use common\models\xhUserTag;
  9. use common\models\xhTrainCourse;
  10. use common\models\xhUser;
  11. use common\models\xhUserAsset;
  12. use common\models\xhTrainUserCourse;
  13. use common\services\xhUserAlipayService;
  14. use common\services\xhUserIntegralService;
  15. use common\services\xhTrainClassService;
  16. use common\services\xhOrderService;
  17. use common\services\xhPayToolService;
  18. use common\services\xhRechargeService;
  19. use common\services\xhMerchantExtendService;
  20. use common\services\xhMerchantAssetService;
  21. use common\services\xhUserAssetService;
  22. use common\services\xhCouponService;
  23. use common\services\xhUserTagService;
  24. use common\services\xhUserTagClassService;
  25. use common\services\xhAdminService;
  26. use common\services\xhMerchantService;
  27. use common\components\stringUtil;
  28. use common\components\weixinUtil;
  29. use common\components\configDict;
  30. use common\components\util;
  31. use common\components\page;
  32. use common\services\xhUserService;
  33. use common\services\xhUserByDayService;
  34. use common\services\xhUserUniteService;
  35. use common\services\xhMerchantCapitalService;
  36. use common\services\xhTMessageService;
  37. class UserController extends BackendController
  38. {
  39. public $sourceImg = [
  40. 0 => 'source_wx.jpg',
  41. 1 => 'source_zfb.jpg',
  42. 2 => 'source_xcx.jpg',
  43. ];
  44. /**
  45. * 学员导入
  46. * @author shish <shish@zhhinc.com>
  47. * @time 2019.5.12
  48. */
  49. public function actionImport()
  50. {
  51. $where = ['merchantId' => $this->merchantId];
  52. $page = isset($get['page']) ? $get['page'] : 1;
  53. $pageSize = 1000;
  54. $data = UserOldDataService::getListData('*', $where, $page, $pageSize, 'id desc');
  55. return $this->render('import', $data);
  56. }
  57. public function actionAll()
  58. {
  59. $get = Yii::$app->request->get();
  60. $query = xhUser::find();
  61. $query->where(['merchantId' => $this->merchantId]);
  62. if (isset($get['content']) && !empty($get['content'])) {
  63. $content = $get['content'];
  64. if (stringUtil::isMobieNumber($content)) {
  65. $query->andWhere(['mobile' => $content]);
  66. } else {
  67. $query->andWhere(['like', 'userName', $content]);
  68. }
  69. }
  70. if (isset($get['class']) && $get['class'] == 1) {
  71. $query->andWhere(['isMember' => 1]);
  72. }
  73. $countQuery = clone $query;
  74. $count = $countQuery->count();
  75. $page = isset($get['page']) ? $get['page'] : 1;
  76. $pageSize = 30;
  77. $offset = ($page - 1) * $pageSize;
  78. $models = $query->offset($offset)->orderBy('visitTime desc')->limit($pageSize)->asArray()->all();
  79. $page = new page($count, $page, $pageSize);
  80. $paging = $page->fpage();
  81. $auth = xhMerchantService::isAuth($this->merchantId);
  82. $merchantTag = xhUserTagClassService::getMerchantTag($this->merchantId);
  83. $merchantAsset = xhMerchantAssetService::getByMerchantId($this->merchantId);
  84. $merchantExtend = xhMerchantExtendService::getByMerchantId($this->merchantId);
  85. $memberIntegral = xhMerchantExtendService::getGradeList($merchantExtend, 'desc');
  86. return $this->render('all', [
  87. 'merchantTag' => $merchantTag,
  88. 'models' => $models,
  89. 'pages' => $paging,
  90. 'merchant' => $this->merchant,
  91. 'memberIntegral' => $memberIntegral,
  92. 'merchantAsset' => $merchantAsset,
  93. 'merchantExtend' => $merchantExtend,
  94. ]);
  95. }
  96. public function actionMember()
  97. {
  98. $get = Yii::$app->request->get();
  99. $query = xhUser::find();
  100. $query->where(['merchantId' => $this->merchantId]);
  101. if (isset($get['content']) && !empty($get['content'])) {
  102. $content = $get['content'];
  103. if (stringUtil::isMobieNumber($content)) {
  104. $query->andWhere(['mobile' => $content]);
  105. } else {
  106. $query->andWhere(['like', 'userName', $content]);
  107. }
  108. }
  109. $query->andWhere(['isMember' => 1]);
  110. $countQuery = clone $query;
  111. $count = $countQuery->count();
  112. $page = isset($get['page']) ? $get['page'] : 1;
  113. $pageSize = 20;
  114. $offset = ($page - 1) * $pageSize;
  115. $models = $query->offset($offset)->orderBy('visitTime desc')->limit($pageSize)->asArray()->all();
  116. $page = new page($count, $page, $pageSize);
  117. $paging = $page->fpage();
  118. $auth = xhMerchantService::isAuth($this->merchantId);
  119. $merchantTag = xhUserTagClassService::getMerchantTag($this->merchantId);
  120. $merchantAsset = xhMerchantAssetService::getByMerchantId($this->merchantId);
  121. $merchantExtend = xhMerchantExtendService::getByMerchantId($this->merchantId);
  122. $memberIntegral = xhMerchantExtendService::getGradeList($merchantExtend, 'desc');
  123. return $this->render('member', [
  124. 'merchantTag' => $merchantTag,
  125. 'models' => $models,
  126. 'pages' => $paging,
  127. 'merchant' => $this->merchant,
  128. 'memberIntegral' => $memberIntegral,
  129. 'merchantAsset' => $merchantAsset,
  130. 'merchantExtend' => $merchantExtend,
  131. ]);
  132. }
  133. public function actionFans()
  134. {
  135. $get = Yii::$app->request->get();
  136. $query = xhUser::find();
  137. $query->where(['merchantId' => $this->merchantId]);
  138. if (isset($get['content']) && !empty($get['content'])) {
  139. $content = $get['content'];
  140. if (stringUtil::isMobieNumber($content)) {
  141. $query->andWhere(['mobile' => $content]);
  142. } else {
  143. $query->andWhere(['like', 'userName', $content]);
  144. }
  145. }
  146. $query->andWhere(['subscribe' => 1]);
  147. $countQuery = clone $query;
  148. $count = $countQuery->count();
  149. $page = isset($get['page']) ? $get['page'] : 1;
  150. $pageSize = 20;
  151. $offset = ($page - 1) * $pageSize;
  152. $models = $query->offset($offset)->orderBy('id desc')->limit($pageSize)->asArray()->all();
  153. $page = new page($count, $page, $pageSize);
  154. $paging = $page->fpage();
  155. $auth = xhMerchantService::isAuth($this->merchantId);
  156. $merchantTag = xhUserTagClassService::getMerchantTag($this->merchantId);
  157. $merchantAsset = xhMerchantAssetService::getByMerchantId($this->merchantId);
  158. $merchantExtend = xhMerchantExtendService::getByMerchantId($this->merchantId);
  159. $memberIntegral = xhMerchantExtendService::getGradeList($merchantExtend, 'desc');
  160. return $this->render('fans', [
  161. 'merchantTag' => $merchantTag,
  162. 'models' => $models,
  163. 'pages' => $paging,
  164. 'merchant' => $this->merchant,
  165. 'memberIntegral' => $memberIntegral,
  166. 'merchantAsset' => $merchantAsset,
  167. 'merchantExtend' => $merchantExtend,
  168. ]);
  169. }
  170. public function actionAlipayUser()
  171. {
  172. $get = Yii::$app->request->get();
  173. $query = xhUserAlipay::find();
  174. $query->where(['merchantId' => $this->merchantId]);
  175. $countQuery = clone $query;
  176. $count = $countQuery->count();
  177. $page = isset($get['page']) ? $get['page'] : 1;
  178. $pageSize = 20;
  179. $offset = ($page - 1) * $pageSize;
  180. $models = $query->offset($offset)->orderBy('updateTime desc')->limit($pageSize)->asArray()->all();
  181. $page = new page($count, $page, $pageSize);
  182. $paging = $page->fpage();
  183. return $this->render('alipayUser', [
  184. 'models' => $models,
  185. 'pages' => $paging,
  186. ]);
  187. }
  188. public function actionAlipayUserDetail()
  189. {
  190. $get = Yii::$app->request->get();
  191. $alipayId = isset($get['alipayId']) ? $get['alipayId'] : '';
  192. $alipay = xhUserAlipayService::getByIds($alipayId, $this->merchantId);
  193. return $this->render('alipayUserDetail', ['alipay' => $alipay]);
  194. }
  195. public function actionDetail()
  196. {
  197. $get = Yii::$app->request->get();
  198. $id = isset($get['id']) ? $get['id'] : 0;
  199. $user = xhUserService::getById($id);
  200. if (empty($user) || $user['merchantId'] != $this->merchantId) {
  201. util::stop('非法访问');
  202. }
  203. $userAsset = xhUserAssetService::getByUserId($id);
  204. //已经查看了此用户,将用户从呼叫列表删除
  205. Yii::$app->redis->executeCommand('ZREM', ["merchant_{$this->merchantId}_new_call", "{$id}"]);
  206. $class = xhTrainClassService::getAllByCondition(['merchantId' => $this->merchantId]);
  207. //取商标的所有用户标签
  208. $merchantTag = xhUserTagClassService::getMerchantTag($this->merchantId);
  209. $userTag = xhUserTagService::getUserTag($id);
  210. $coupon = xhCouponService::getUserCoupon($id);//取代金劵
  211. $merchantExtend = xhMerchantExtendService::getByMerchantId($this->merchantId);
  212. $memberIntegral = xhMerchantExtendService::getGradeList($merchantExtend, 'desc');
  213. $freight = configDict::getConfig('freight');//运费计算
  214. $alipayId = 0;
  215. $alipayInfo = [];
  216. if (!empty($user['alipayId'])) {
  217. $alipayId = $user['alipayId'];
  218. $alipayInfo = xhUserAlipayService::getByIds($alipayId, $this->merchantId);
  219. }
  220. return $this->render('detail', [
  221. 'merchantExtend' => $merchantExtend,
  222. 'userTag' => $userTag,
  223. 'coupon' => $coupon,
  224. 'merchantTag' => $merchantTag,
  225. 'class' => $class,
  226. 'user' => $user,
  227. 'userAsset' => $userAsset,
  228. 'memberIntegral' => $memberIntegral,
  229. 'freight' => $freight,
  230. 'merchant' => $this->merchant,
  231. 'alipayInfo' => $alipayInfo,
  232. ]);
  233. }
  234. /**
  235. * 升级为会员
  236. */
  237. public function actionUpgrade()
  238. {
  239. $get = Yii::$app->request->get();
  240. $adminId = $this->adminId;
  241. $admin = xhAdminService::getById($adminId);
  242. if (isset($get['confirmPassword']) == false) {
  243. util::failInfo('请填写确认密码');
  244. }
  245. if (isset($get['memberLevel']) == false || empty($get['memberLevel'])) {
  246. util::failInfo('请选择等级数');
  247. }
  248. $userId = isset($get['userId']) ? $get['userId'] : 0;
  249. $memberLevel = $get['memberLevel'];
  250. $user = xhUserService::getById($userId);
  251. if (empty($user) || $user['merchantId'] != $this->merchantId) {
  252. util::failInfo('客户不存在');
  253. }
  254. if (empty($user['mobile'])) {
  255. util::failInfo('客户还没有绑定手机号');
  256. }
  257. $mobile = $user['mobile'];
  258. $oldData = UserOldDataService::getByCondition(['merchantId' => $this->merchantId, 'mobile' => $mobile]);
  259. if (!empty($oldData)) {
  260. util::failInfo('这个客人有老客户记录,无法手动升级');
  261. }
  262. $confirmPassword = $get['confirmPassword'];
  263. if (md5($confirmPassword) != $admin['confirmPassword']) {
  264. util::failInfo('确认密码有误');
  265. }
  266. $grade = xhMerchantExtendService::getGradeList($this->merchantExtend, 'desc');
  267. $newLevelPoint = $grade[$memberLevel]['integral'];//升级到当前级别需要的积分数
  268. $userAsset = xhUserAssetService::getByUserId($userId);//用户资产
  269. if (!empty($userAsset['isMember']) && $userAsset['memberLevel'] >= $memberLevel) {
  270. util::failInfo('客户已经达到此级别了');
  271. }
  272. $connection = Yii::$app->db;//事务处理
  273. $transaction = $connection->beginTransaction();
  274. try {
  275. $addPoint = $newLevelPoint - $userAsset['integral'];
  276. $upData['integral'] = $newLevelPoint;//升级后的积分
  277. $upData['memberLevel'] = $memberLevel;
  278. $upData['isMember'] = 1;
  279. xhUserAssetService::updateByUserId($userId, $upData);
  280. $old = ['mobile' => $mobile, 'merchantId' => $this->merchantId, 'createTime' => date("Y-m-d H:i:s"), 'integral' => $addPoint, 'status' => 1];
  281. $return = UserOldDataService::add($old);
  282. if (empty($return)) {
  283. util::failInfo('升级失败');
  284. }
  285. $targetId = $return['id'];
  286. $now = time();
  287. $date = date("Y-m-d H:i", $now);
  288. $integralData = [
  289. 'userId' => $userId,
  290. 'userName' => $user['userName'],
  291. 'merchantId' => $this->merchantId,
  292. 'relateId' => (string)$targetId,
  293. 'integral' => $newLevelPoint,
  294. 'num' => $addPoint,
  295. 'io' => 1,
  296. 'payWay' => 4,
  297. 'alipayId' => '',
  298. 'event' => '店长操作升级',
  299. 'operatorId' => $userId,
  300. 'createTime' => $date,
  301. 'capitalType' => 0,
  302. 'addTime' => $now,
  303. ];
  304. xhUserIntegralService::add($integralData);//用户兑换型积分流水增加
  305. $transaction->commit();
  306. } catch (Exception $e) {
  307. $transaction->rollBack();
  308. util::failInfo();
  309. }
  310. $allTM = xhTMessageService::getList($this->merchantId);
  311. $openId = $user['openId'];
  312. $shortTempId = 'OPENTM205211943';//升级通知
  313. if (isset($allTM[$shortTempId])) {
  314. $tempId = $allTM[$shortTempId];
  315. $data = [
  316. "touser" => $openId, "template_id" => $tempId, "url" => '',
  317. "data" => [
  318. "first" => ["value" => "恭喜,您已经升为{$memberLevel}级会员。", "color" => "#173177"],
  319. "keyword1" => ["value" => $user['userName'], "color" => "#173177"],
  320. "keyword2" => ["value" => $date, "color" => "#173177"],
  321. "remark" => ["value" => "点击查看会员权益", "color" => "#173177"],
  322. ]];
  323. weixinUtil::sendTaskInform($data, $this->merchant);
  324. }
  325. util::successInfo();
  326. }
  327. /**
  328. * 充值
  329. */
  330. public function actionRecharge()
  331. {
  332. $get = Yii::$app->request->get();
  333. $rechargePassword = isset($get['rechargePassword']) ? $get['rechargePassword'] : '';
  334. $adminId = $this->adminId;
  335. $admin = xhAdminService::getById($adminId);
  336. if (empty($admin['confirmPassword'])) {
  337. util::failInfo('您还没有设置确认密码');
  338. }
  339. if (md5($rechargePassword) != $admin['confirmPassword']) {
  340. util::failInfo('确认密码有误哦');
  341. }
  342. $userId = isset($get['userId']) ? $get['userId'] : 0;
  343. $rechargeAmount = isset($get['rechargeAmount']) ? $get['rechargeAmount'] : 1;
  344. $user = xhUserService::getById($userId);
  345. if (empty($user) || $user['merchantId'] != $this->merchantId) {
  346. util::failInfo('访问出错,请联系网站管理员');
  347. }
  348. $userAsset = xhUserAssetService::getByUserId($userId);
  349. if (empty($userAsset)) {
  350. util::failInfo('操作出错,请与网站管理员联系');
  351. }
  352. $totalBalance = $userAsset['balance'] + $rechargeAmount;
  353. $totalRecharge = $userAsset['totalRecharge'] + $rechargeAmount;
  354. $upData['balance'] = $totalBalance;
  355. $upData['totalRecharge'] = $totalRecharge;
  356. $return = xhRechargeService::recharge($rechargeAmount, $user, $this->adminId, $this->merchant, $this->merchantExtend, $this->merchantAsset);
  357. if ($return['code'] == 'A0001') {
  358. util::successInfo('充值成功');
  359. }
  360. util::successInfo('充值失败');
  361. }
  362. /**
  363. * 现金支付,转店主微信,转店主支付宝
  364. */
  365. public function actionCashPay()
  366. {
  367. $post = Yii::$app->request->post();
  368. $extend = $this->merchantExtend;
  369. //dump($post);die;
  370. $getUid = Yii::$app->request->get('userId');
  371. $userId = isset($getUid) ? $getUid : 0;
  372. $amount = isset($post['consumeAmount']) ? $post['consumeAmount'] : 1;
  373. $couponId = isset($post['couponId']) ? $post['couponId'] : 1;
  374. $user = xhUserService::getById($userId, $this->merchantId);
  375. /*if($user['merchantId'] != $this->merchantId){
  376. util::failInfo('非法访问');
  377. }*/
  378. if (!empty($user) && empty($user['subscribe'])) {
  379. util::failInfo('客户要关注公众号才能结算');
  380. }
  381. /*if(!empty($couponId)){
  382. $coupon = xhCouponService::getById($couponId);
  383. if($coupon['merchantId'] != $this->merchantId){
  384. util::failInfo('非法代金劵');
  385. }
  386. if($coupon['useStatus'] == 1 || time() > $coupon['deadline']){
  387. util::failInfo('代金劵已经失效');
  388. }
  389. if($coupon['meetAmount'] > $amount){
  390. util::failInfo('消费不足'.$coupon['meetAmount'].'元');
  391. }
  392. }*/
  393. $payWay = configDict::getConfig('payWay', 'cashPay');
  394. $payStyle = configDict::getConfig('payStyle', 'cashPay');
  395. $now = time();
  396. $expireTime = $now + 300;//订单5分钟后过期
  397. $payAdd['prePrice'] = $amount;
  398. $payAdd['actPrice'] = $amount;
  399. $payAdd['payWay'] = $payWay;
  400. $payAdd['payStyle'] = $payStyle;
  401. $payAdd['payStatus'] = 0;
  402. $payAdd['userId'] = $userId;
  403. $payAdd['merchantId'] = $this->merchantId;
  404. $payAdd['createTime'] = date("Y-m-d H:i:s", $now);
  405. $payAdd['deadline'] = $expireTime;
  406. xhOrderService::formatPost($payAdd, $post);
  407. $order = xhOrderService::add($payAdd);
  408. $id = $order['id'];
  409. $typeList = configDict::getConfig('capitalType');
  410. $capitalType = $typeList['xhOrder']['id'];
  411. $return = xhPayToolService::cashPay($id, $amount, $capitalType, $couponId);
  412. if ($return['code'] == 'A0001') {
  413. util::successInfo('登记成功');
  414. } else {
  415. Yii::warning(json_encode($return));
  416. }
  417. util::failInfo('登记没有成功');
  418. }
  419. /**
  420. * 重置支付密码
  421. */
  422. public function actionResetPayPassword()
  423. {
  424. $get = Yii::$app->request->get();
  425. $id = isset($get['id']) ? $get['id'] : 0;
  426. $user = xhUserService::getById($id);
  427. if (empty($user) || $user['merchantId'] != $this->merchantId) {
  428. util::failInfo('没有这个客户');
  429. }
  430. if (empty($user['subscribe'])) {
  431. util::failInfo('客户要先关注公众号哦');
  432. }
  433. $rand = stringUtil::getRandNum(6);
  434. xhUserService::updateById($id, ['payPassword' => md5($rand)]);
  435. $openId = $user['openId'];
  436. $allTM = xhTMessageService::getList($this->merchantId);
  437. $shortTempId = 'OPENTM207430125';
  438. if (isset($allTM[$shortTempId])) {
  439. $tempId = $allTM[$shortTempId];
  440. $url = Yii::$app->params['frontUrl'] . '/center/password?account=' . $this->merchant['id'];
  441. $data = [
  442. "touser" => $openId, "template_id" => $tempId, "url" => $url,
  443. "data" => ["first" => ["value" => '操作成功', "color" => "#173177"],
  444. "keyword1" => ["value" => "你的支付密码已经重置为:" . $rand, "color" => "#173177"],
  445. "keyword2" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
  446. "remark" => ["value" => "点此修改成好记的密码哦", "color" => "#173177"]]];
  447. weixinUtil::sendTaskInform($data, $this->merchant);
  448. }
  449. util::successInfo();
  450. }
  451. /**
  452. * 导出用户,备份用户
  453. */
  454. public function actionExport()
  455. {
  456. $query = xhUserAsset::find();
  457. $query->where(['merchantId' => $this->merchantId])->andWhere(['>', 'integral', 0]);
  458. $userAsset = $query->orderBy('integral desc')->all();
  459. if (empty($userAsset)) {
  460. echo '没有获得积分用户';
  461. Yii::$app->end();
  462. }
  463. $objectPHPExcel = new \PHPExcel();
  464. $objectPHPExcel->setActiveSheetIndex(0);
  465. $memberCount = xhUserAsset::find()->andWhere(['isMember' => 1, 'merchantId' => $this->merchantId])->count('id');//会员数
  466. $allUsercount = xhUserAsset::find()->andWhere(['merchantId' => $this->merchantId])->count('id');//用户数
  467. //报表头的输出
  468. $objectPHPExcel->getActiveSheet()->mergeCells('B1:G1');
  469. $objectPHPExcel->getActiveSheet()->setCellValue('B1', '用户信息表');
  470. $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('B2', '用户信息表');
  471. $objectPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getFont()->setSize(24);
  472. $objectPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  473. $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('B2', '日期:' . date("Y年m月j日"));
  474. $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('F2', '用户数:' . $allUsercount);
  475. $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('G2', '会员数:' . $memberCount);
  476. $objectPHPExcel->setActiveSheetIndex(0)->getStyle('F2')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);//右居中
  477. $objectPHPExcel->setActiveSheetIndex(0)->getStyle('G2')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);//右居中
  478. //表格头的输出
  479. $objectPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(5);
  480. $objectPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(7);
  481. $objectPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
  482. $objectPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(17);
  483. $objectPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
  484. $objectPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
  485. $objectPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(22);
  486. $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('B3', '编号');
  487. $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('C3', '昵称');
  488. $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('D3', '会员等级');
  489. $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('E3', '余额');
  490. $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('F3', '积分');
  491. $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('G3', '创建日期');
  492. //设置居中
  493. $objectPHPExcel->getActiveSheet()->getStyle('B3:G3')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  494. //设置边框
  495. $objectPHPExcel->getActiveSheet()->getStyle('B3:G3')->getBorders()->getTop()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
  496. $objectPHPExcel->getActiveSheet()->getStyle('B3:G3')->getBorders()->getLeft()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
  497. $objectPHPExcel->getActiveSheet()->getStyle('B3:G3')->getBorders()->getRight()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
  498. $objectPHPExcel->getActiveSheet()->getStyle('B3:G3')->getBorders()->getBottom()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
  499. $objectPHPExcel->getActiveSheet()->getStyle('B3:G3')->getBorders()->getVertical()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
  500. //设置颜色
  501. $objectPHPExcel->getActiveSheet()->getStyle('B3:G3')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF66CCCC');
  502. foreach ($userAsset as $subKey => $subMUser) {
  503. //明细的输出
  504. $objectPHPExcel->getActiveSheet()->setCellValue('B' . ($subKey + 4), $subKey + 1);
  505. $objectPHPExcel->getActiveSheet()->setCellValue('C' . ($subKey + 4), $subMUser->xhUser->userName);
  506. $objectPHPExcel->getActiveSheet()->setCellValue('D' . ($subKey + 4), $subMUser->memberLevel);
  507. $objectPHPExcel->getActiveSheet()->setCellValue('E' . ($subKey + 4), $subMUser->balance);
  508. $objectPHPExcel->getActiveSheet()->setCellValue('F' . ($subKey + 4), $subMUser->integral);
  509. $objectPHPExcel->getActiveSheet()->setCellValue('G' . ($subKey + 4), $subMUser->createTime);
  510. //设置边框
  511. $currentRowNum = $subKey + 4;
  512. $objectPHPExcel->getActiveSheet()->getStyle('B' . ($subKey + 4) . ':G' . $currentRowNum)->getBorders()->getTop()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
  513. $objectPHPExcel->getActiveSheet()->getStyle('B' . ($subKey + 4) . ':G' . $currentRowNum)->getBorders()->getLeft()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
  514. $objectPHPExcel->getActiveSheet()->getStyle('B' . ($subKey + 4) . ':G' . $currentRowNum)->getBorders()->getRight()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
  515. $objectPHPExcel->getActiveSheet()->getStyle('B' . ($subKey + 4) . ':G' . $currentRowNum)->getBorders()->getBottom()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
  516. $objectPHPExcel->getActiveSheet()->getStyle('B' . ($subKey + 4) . ':G' . $currentRowNum)->getBorders()->getVertical()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
  517. }
  518. //设置分页显示
  519. //$objectPHPExcel->getActiveSheet()->setBreak( 'I55' , \PHPExcel_Worksheet::BREAK_ROW );
  520. //$objectPHPExcel->getActiveSheet()->setBreak( 'I10' , \PHPExcel_Worksheet::BREAK_COLUMN );
  521. $objectPHPExcel->getActiveSheet()->getPageSetup()->setHorizontalCentered(true);
  522. $objectPHPExcel->getActiveSheet()->getPageSetup()->setVerticalCentered(false);
  523. ob_end_clean();
  524. ob_start();
  525. header('Content-Type : application/vnd.ms-excel');
  526. header('Content-Disposition:attachment;filename="' . $this->merchant['merchantName'] . '会员' . date("Ymj") . '.xls"');
  527. $objWriter = \PHPExcel_IOFactory::createWriter($objectPHPExcel, 'Excel5');
  528. $objWriter->save('php://output');
  529. }
  530. /**
  531. * 报名培训
  532. */
  533. public function actionApplyTrain()
  534. {
  535. $get = Yii::$app->request->get();
  536. $userId = $get['userId'];
  537. $user = xhUserService::getById($userId);
  538. if (empty($user) || $user['merchantId'] != $this->merchantId) {
  539. util::failInfo('学员不存在');
  540. }
  541. if (empty($user['subscribe'])) {
  542. util::failInfo('学员还没有关注公众号哦~');
  543. }
  544. $student = xhStudent::getByCondition(['userId' => $userId, 'merchantId' => $this->merchantId]);
  545. if (!empty($student)) {
  546. util::failInfo('已经报过名了哦~');
  547. }
  548. $classId = isset($get['classId']) ? $get['classId'] : 0;
  549. $class = xhTrainClassService::getById($classId);
  550. if (empty($class)) {
  551. util::failInfo('课程不存在哦~');
  552. }
  553. $nowTime = time();
  554. $stuData = ['userId' => $userId, 'merchantId' => $this->merchantId, 'registerTime' => $nowTime, 'classId' => $class['id'],
  555. 'addTime' => $nowTime, 'modTime' => $nowTime, 'tuition' => $class['tuition'], 'className' => $class['name'], 'lesson' => $class['lesson']];
  556. $student = xhStudent::add($stuData);
  557. $course = xhTrainCourse::getAllByCondition(['classId' => $classId]);
  558. $userCourse = [];
  559. foreach ($course as $key => $val) {
  560. $userCourse[] = ['courseId' => $val['id'], 'courseName' => $val['name'], 'courseIntro' => $val['intro'], 'classId' => $classId, 'studentId' => $student['id'], 'userId' => $userId, 'merchantId' => $this->merchantId];
  561. }
  562. xhTrainUserCourse::batchAdd($userCourse);
  563. xhUserService::updateById($userId, ['identity' => 1]);
  564. $allTM = xhTMessageService::getList($this->merchantId);
  565. $openId = $user['openId'];
  566. $shortTempId = 'OPENTM401027382';
  567. if (isset($allTM[$shortTempId])) {
  568. $tempId = $allTM[$shortTempId];
  569. $data = array(
  570. "touser" => $openId,
  571. "template_id" => $tempId,//模板id,从公众平台后台取得
  572. "url" => $this->frontUrl . '/center/student-card?account=' . $this->merchant['id'],
  573. "data" => array(
  574. "first" => array(
  575. "value" => "恭喜,您已经成功报名。",
  576. "color" => "#173177"
  577. ),
  578. "keyword1" => array(
  579. "value" => $class['name'],
  580. "color" => "#173177"
  581. ),
  582. "keyword2" => array(
  583. "value" => date("Y-m-d H:i"),
  584. "color" => "#173177"
  585. ),
  586. "remark" => array(
  587. "value" => "您的学员卡已经激活,点此查看课程内容",
  588. "color" => "#173177"
  589. ),
  590. ),
  591. );
  592. }
  593. weixinUtil::sendTaskInform($data, $this->merchant);
  594. util::successInfo('报名成功~');
  595. }
  596. public function actionRemark()
  597. {
  598. $get = Yii::$app->request->get();
  599. $userId = isset($get['userId']) ? $get['userId'] : 0;
  600. $user = xhUserService::getById($userId);
  601. if (empty($user) || $user['merchantId'] != $this->merchantId) {
  602. util::failInfo('用户不存在');
  603. }
  604. $remark = isset($get['remark']) ? $get['remark'] : '';
  605. xhUserService::updateById($userId, ['remark' => $remark]);
  606. util::successInfo();
  607. }
  608. public function actionTagUserList()
  609. {
  610. $get = Yii::$app->request->get();
  611. $tagId = isset($get['tagId']) ? $get['tagId'] : 0;
  612. $tagInfo = xhUserTagClassService::getByCondition(['tagId' => $tagId]);
  613. if (empty($tagInfo) || $tagInfo['merchantId'] != $this->merchantId) {
  614. util::stop('不合法标签');
  615. }
  616. $query = xhUserTag::find();
  617. $query->where(['tagId' => $tagId]);
  618. $query->orderBy('id desc');
  619. $countQuery = clone $query;
  620. $count = $countQuery->count();
  621. $page = isset($get['page']) ? $get['page'] : 1;
  622. $pageSize = 20;
  623. $offset = ($page - 1) * $pageSize;
  624. $models = $query->offset($offset)->orderBy('id desc')->limit($pageSize)->asArray()->all();
  625. $page = new page($count, $page, $pageSize);
  626. $paging = $page->fpage();
  627. $merchantTag = xhUserTagClassService::getMerchantTag($this->merchantId);
  628. return $this->render('tagUserList', ['models' => $models, 'paging' => $paging, 'merchantTag' => $merchantTag, 'tagInfo' => $tagInfo]);
  629. }
  630. public function actionTag()
  631. {
  632. $tag = xhUserTagClassService::getAllByCondition(['merchantId' => $this->merchantId]);
  633. return $this->render('tag', ['tag' => $tag]);
  634. }
  635. /**
  636. * 添加用户标签
  637. */
  638. public function actionTagAdd()
  639. {
  640. $post = Yii::$app->request->post();
  641. if (isset($post['tagName']) == false || empty($post['tagName'])) {
  642. util::failInfo('请填写标签名称');
  643. }
  644. $name = $post['tagName'];
  645. $tagArr = xhUserTagClassService::getMerchantTag($this->merchantId);
  646. if (!empty($tagArr) && in_array($name, $tagArr)) {
  647. util::failInfo('标签已经存在了');
  648. }
  649. $return = weixinUtil::createTag($this->merchant, $name);
  650. if (isset($return['errcode']) == false) {
  651. $tagId = $return['tag']['id'];
  652. $data = ['tagId' => $tagId, 'name' => $name, 'merchantId' => $this->merchantId];
  653. xhUserTagClassService::add($data, $this->merchantId);
  654. util::successInfo();
  655. }
  656. $errCode = $return['errcode'];
  657. $errList = weixinUtil::$errCodes;
  658. $msg = $errList[$errCode];
  659. util::failInfo($msg);
  660. }
  661. /**
  662. * 删除用户标签
  663. */
  664. public function actionTagDel()
  665. {
  666. $get = Yii::$app->request->get();
  667. if (isset($get['tagId']) == false || empty($get['tagId'])) {
  668. util::failInfo('请选择你要删除的标签');
  669. }
  670. $tagId = $get['tagId'];
  671. $status = xhUserTagService::getUserByTagId($tagId);
  672. if ($status) {
  673. util::failInfo('标签下还有用户,无法删除');
  674. }
  675. $tag = xhUserTagClassService::getByCondition(['tagId' => $tagId, 'merchantId' => $this->merchantId]);
  676. if (empty($tag)) {
  677. util::failInfo('标签不存在');
  678. }
  679. if ($tag['merchantId'] != $this->merchantId) {
  680. util::failInfo('非法操作');
  681. }
  682. $wxTagId = $tag['tagId'];
  683. $return = weixinUtil::delTag($this->merchant, $wxTagId);
  684. if (isset($return['errcode']) && $return['errcode'] == 0) {
  685. xhUserTagClassService::deleteByCondition(['tagId' => $tagId, 'merchantId' => $this->merchantId], $this->merchantId);
  686. util::successInfo();
  687. }
  688. $errCode = $return['errcode'];
  689. $errList = weixinUtil::$errCodes;
  690. $msg = $errList[$errCode];
  691. util::failInfo($msg);
  692. }
  693. /**
  694. * 修改标签
  695. */
  696. public function actionTagMod()
  697. {
  698. $get = Yii::$app->request->get();
  699. if (isset($get['id']) == false || empty($get['id'])) {
  700. util::failInfo('请选择标签');
  701. }
  702. $id = $get['id'];
  703. $tag = xhUserTagClassService::getByCondition(['id' => $id]);
  704. if (empty($tag)) {
  705. util::failInfo('标签已删除');
  706. }
  707. if ($tag['merchantId'] != $this->merchantId) {
  708. util::failInfo('非法访问');
  709. }
  710. $tagId = $tag['tagId'];
  711. $name = $get['tagName'];
  712. $return = weixinUtil::modTag($this->merchant, $tagId, $name);
  713. if (isset($return['errcode']) && $return['errcode'] == 0) {
  714. $data = ['name' => $name];
  715. xhUserTagClassService::updateById($id, $data, $this->merchantId);
  716. util::successInfo('操作成功');
  717. }
  718. $errCode = $return['errcode'];
  719. $errList = weixinUtil::$errCodes;
  720. $msg = $errList[$errCode];
  721. util::failInfo($msg);
  722. }
  723. /**
  724. * 对每个用户设置标签
  725. */
  726. public function actionTagSet()
  727. {
  728. $get = Yii::$app->request->get();
  729. $userId = isset($get['userId']) ? $get['userId'] : 0;
  730. $user = xhUserService::getById($userId);
  731. if (empty($user) || $user['merchantId'] != $this->merchantId) {
  732. util::failInfo('非法用户');
  733. }
  734. $tagId = isset($get['tagId']) ? $get['tagId'] : '';
  735. $merchantTag = xhUserTagClassService::getMerchantTag($this->merchantId);
  736. $mTag = array_flip($merchantTag);
  737. //防止非法标签id
  738. if (in_array($tagId, $mTag) == false) {
  739. util::failInfo('非法标签');
  740. }
  741. $userTag = xhUserTagService::getUserTag($userId);
  742. if (count($userTag) >= 3) {
  743. util::failInfo('最多只能设置三个标签哦');
  744. }
  745. if (in_array($tagId, $userTag)) {
  746. util::failInfo('此标签已经添加过了');
  747. }
  748. $openIdList = [$user['openId']];
  749. $return = weixinUtil::membersBatchTag($this->merchant, $openIdList, $tagId);
  750. if (isset($return['errcode']) == false) {
  751. util::failInfo('操作未成功,微信服务器没有返回');
  752. }
  753. if ($return['errcode'] != 0) {
  754. $errCode = $return['errcode'];
  755. $errList = weixinUtil::$errCodes;
  756. $msg = isset($errList[$errCode]) ? $errList[$errCode] : '';
  757. util::failInfo($msg);
  758. }
  759. $addTagData = ['merchantId' => $this->merchantId, 'tagId' => $tagId, 'userId' => $userId];
  760. xhUserTagService::add($addTagData);
  761. util::successInfo();
  762. }
  763. /**
  764. * 删除用户的标签
  765. */
  766. public function actionTagRemove()
  767. {
  768. $get = Yii::$app->request->get();
  769. $userId = isset($get['userId']) ? $get['userId'] : 0;
  770. $user = xhUserService::getById($userId);
  771. if (empty($user) || $user['merchantId'] != $this->merchantId) {
  772. util::failInfo('非法用户');
  773. }
  774. $tagId = isset($get['tagId']) ? $get['tagId'] : '';
  775. $merchantTag = xhUserTagClassService::getMerchantTag($this->merchantId);
  776. $mTag = array_flip($merchantTag);
  777. //防止非法标签id
  778. if (in_array($tagId, $mTag) == false) {
  779. util::failInfo('非法标签');
  780. }
  781. $openIdList = [$user['openId']];
  782. $return = weixinUtil::membersCancelTag($this->merchant, $openIdList, $tagId);
  783. if (isset($return['errcode']) == false) {
  784. util::failInfo('操作未成功,微信服务器没有返回');
  785. }
  786. if ($return['errcode'] != 0) {
  787. $errCode = $return['errcode'];
  788. $errList = weixinUtil::$errCodes;
  789. $msg = isset($errList[$errCode]) ? $errList[$errCode] : '';
  790. util::failInfo($msg);
  791. }
  792. xhUserTagService::deleteByCondition(['tagId' => $tagId, 'merchantId' => $this->merchantId, 'userId' => $userId]);
  793. util::successInfo('操作成功');
  794. }
  795. /**
  796. * 给多个用户添加标签
  797. */
  798. public function actionBatchAddUserTag()
  799. {
  800. $get = Yii::$app->request->get();
  801. if (isset($get['tagId']) == false || empty($get['tagId'])) {
  802. util::failInfo('请选择标签');
  803. }
  804. if (isset($get['userIdStr']) == false || empty($get['userIdStr'])) {
  805. util::failInfo('请选择用户');
  806. }
  807. $tagId = $get['tagId'];
  808. $userIdStr = trim($get['userIdStr']);
  809. $userIdList = explode(',', $userIdStr);
  810. $userIds = xhUserTagService::getUserIdByTagId($tagId, $this->merchantId);//取标签下的用户
  811. $toDoIds = array_diff($userIdList, $userIds);
  812. if (empty($toDoIds)) {
  813. util::successInfo('全部用户已经设置此标签了~');
  814. }
  815. $openIdList = [];
  816. $toSaveData = [];
  817. foreach ($toDoIds as $doKey => $doUserId) {
  818. $userInfo = xhUserService::getById($doUserId);
  819. if ($userInfo['merchantId'] == $this->merchantId) {
  820. $openIdList[] = $userInfo['openId'];
  821. $toSaveData[] = ['merchantId' => $this->merchantId, 'tagId' => $tagId, 'userId' => $doUserId];
  822. }
  823. }
  824. $return = weixinUtil::membersBatchTag($this->merchant, $openIdList, $tagId);//批量为用户打标签
  825. if (isset($return['errcode']) == false) {
  826. util::failInfo('操作失败');
  827. }
  828. if ($return['errcode'] == 0) {
  829. xhUserTagService::batchAdd($toSaveData);
  830. util::successInfo('操作成功');
  831. }
  832. $errCode = $return['errcode'];
  833. $errList = weixinUtil::$errCodes;
  834. $msg = isset($errList[$errCode]) ? $errList[$errCode] : '操作失败';
  835. util::failInfo($msg);
  836. }
  837. /**
  838. * 发放代金劵
  839. */
  840. public function actionGrantCoupon()
  841. {
  842. $get = Yii::$app->request->get();
  843. $userId = isset($get['userId']) ? $get['userId'] : 0;
  844. $userInfo = xhUserService::getById($userId);
  845. $merchantId = isset($userInfo['merchantId']) ? $userInfo['merchantId'] : 0;
  846. if ($this->merchantId != $merchantId) {
  847. util::failInfo('不是你的用户');
  848. }
  849. $duration = isset($get['duration']) && !empty($get['duration']) ? $get['duration'] : 60;
  850. $amount = isset($get['amount']) && !empty($get['amount']) ? $get['amount'] : 5;
  851. $meetAmount = isset($get['meetAmount']) && !empty($get['meetAmount']) ? $get['meetAmount'] : 150;
  852. if ($meetAmount <= $amount) {
  853. util::failInfo('消费金额要大于代金劵金额');
  854. }
  855. $get['beginTime'] = isset($get['beginTime']) && !empty($get['beginTime']) ? strtotime($get['beginTime']) : time();
  856. $get['deadline'] = $get['beginTime'] + $duration * 86400;
  857. $get['amount'] = $amount;
  858. $get['meetAmount'] = $meetAmount;
  859. $get['createTime'] = date("Y-m-d H:i:s");
  860. $get['merchantId'] = $this->merchantId;
  861. $get['userId'] = $userId;
  862. $get['number'] = 'CO' . stringUtil::buildOrderNo($userId);//代金劵编号
  863. xhCouponService::add($get, $userId);
  864. $allTM = xhTMessageService::getList($this->merchantId);
  865. $shortTempId = 'OPENTM207112032';//收入提醒
  866. if (isset($allTM[$shortTempId])) {
  867. $tempId = $allTM[$shortTempId];
  868. $openId = $userInfo['openId'];
  869. $data = ["touser" => $openId, "template_id" => $tempId,
  870. "url" => $this->frontUrl . '/center/coupon?account=' . $this->merchant['id'],
  871. "data" => [
  872. "first" => ["value" => "亲,您获得一张代金劵哦。", "color" => "#173177"],
  873. "keyword1" => ["value" => '代金劵', "color" => "#173177"],
  874. "keyword2" => ["value" => $amount . '元', "color" => "#173177"],
  875. "keyword3" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
  876. "remark" => ["value" => "点击查看详情", "color" => "#173177"]]];
  877. weixinUtil::sendTaskInform($data, $this->merchant);
  878. }
  879. util::successInfo();
  880. }
  881. public function actionTrend()
  882. {
  883. $fans = xhUserByDayService::getLatestNum($this->merchantId, 29);
  884. return $this->render('trend', ['fans' => $fans,]);
  885. }
  886. /**
  887. * 将支付宝关联上微信号,积分迁移到微信号上
  888. */
  889. public function actionRelateUser()
  890. {
  891. $get = Yii::$app->request->get();
  892. $userId = isset($get['userId']) ? $get['userId'] : 0;
  893. $alipayId = isset($get['alipayId']) ? $get['alipayId'] : 0;
  894. $relation = xhUserAlipayService::getByIds($alipayId, $this->merchantId);
  895. if (empty($relation)) {
  896. util::failInfo('消费信息不存在');
  897. }
  898. if (isset($relation['userId']) && !empty($relation['userId'])) {
  899. util::failInfo('帐号已经绑定过了');
  900. }
  901. $user = xhUserService::getById($userId);
  902. if ($user['merchantId'] != $this->merchantId) {
  903. util::failInfo('不是您的用户');
  904. }
  905. $openId = $user['openId'];
  906. $userName = $user['userName'];
  907. if (!empty($user['alipayId'])) {
  908. util::failInfo($userName . '已经绑定过支付宝了');
  909. }
  910. xhUserAlipayService::updateByIds($alipayId, $this->merchantId, ['openId' => $openId, 'userId' => $userId, 'status' => 1]);
  911. $merchant = $this->merchant;
  912. $merchantExtend = $this->merchantExtend;
  913. $merchantId = $this->merchantId;
  914. $date = date("Y-m-d H:i:s");
  915. $now = time();
  916. $userAsset = xhUserAssetService::getByUserId($userId);
  917. $capitalTypeList = configDict::getConfig('capitalType');
  918. $capitalType = $capitalTypeList['xhUserUnite']['id'];
  919. $point = $relation['point'];
  920. $addIntegral = $point;
  921. $addPoint = $point;
  922. $totalExpend = $relation['totalExpend'];
  923. $uniteData = [
  924. 'alipayId' => $alipayId,
  925. 'merchantId' => $this->merchantId,
  926. 'userId' => $userId,
  927. 'point' => $point,
  928. 'totalExpend' => $totalExpend,
  929. 'operateId' => $this->adminId,
  930. 'addTime' => time(),
  931. 'createTime' => $date,
  932. ];
  933. $order = xhUserUniteService::add($uniteData);
  934. $orderId = $order['id'];
  935. $payWay = configDict::getConfig('payWay', 'alipay');
  936. $userIntegral = stringUtil::calcAdd($userAsset['integral'], $point);
  937. $userPoint = stringUtil::calcAdd($userAsset['point'], $point);
  938. $totalExpend = stringUtil::calcAdd($userAsset['totalExpend'], $totalExpend);
  939. $upAssetData = [];
  940. $upAssetData['integral'] = $userIntegral;
  941. $upAssetData['point'] = $userPoint;
  942. $upAssetData['totalExpend'] = $totalExpend;
  943. xhUserAssetService::ioChangeAsset($user, $userAsset, $upAssetData, $merchant, $merchantExtend, $order, $capitalType);//用户资产改变
  944. xhUserService::updateById($userId, ['alipayId' => $alipayId]);
  945. $integralData = [
  946. 'userId' => $userId,
  947. 'userName' => $userName,
  948. 'merchantId' => $merchantId,
  949. 'relateId' => (string)$orderId,
  950. 'integral' => $userIntegral,
  951. 'num' => $addIntegral,
  952. 'io' => 1,
  953. 'payWay' => $payWay,
  954. 'alipayId' => $alipayId,
  955. 'event' => '绑定支付宝帐号获得积分',
  956. 'operatorId' => $userId,
  957. 'createTime' => $date,
  958. 'addTime' => $now,
  959. 'capitalType' => $capitalType,
  960. ];
  961. xhUserIntegralService::add($integralData);//用户兑换型积分流水增加
  962. xhMerchantCapitalService::updateByCondition(['alipayId' => $alipayId, 'merchantId' => $this->merchantId], ['userId' => $userId, 'userName' => $userName]);
  963. xhOrderService::updateByCondition(['alipayId' => $alipayId, 'merchantId' => $this->merchantId], ['userId' => $userId]);
  964. util::successInfo();
  965. }
  966. /**
  967. * 关联前获取用户信息
  968. */
  969. public function actionGetUser()
  970. {
  971. $get = Yii::$app->request->get();
  972. $id = isset($get['id']) ? $get['id'] : 0;
  973. $user = xhUserService::getById($id);
  974. if ($user['subscribe'] == 0) {
  975. util::failInfo('没有关注公众号');
  976. }
  977. if ($user['merchantId'] != $this->merchantId) {
  978. util::failInfo('非法操作');
  979. }
  980. $largeImg = $user['avatar'];
  981. $avatarList = xhUserService::getAvatarList($largeImg);
  982. $avatar = $avatarList['small'];
  983. util::successInfo('操作成功', 'A0001', ['id' => $id, 'avatar' => $avatar, 'userName' => $user['userName']]);
  984. }
  985. public function actionStudent()
  986. {
  987. $get = Yii::$app->request->get();
  988. $query = xhStudent::find();
  989. $countQuery = clone $query;
  990. $count = $countQuery->count();
  991. $page = isset($get['page']) ? $get['page'] : 1;
  992. $pageSize = 20;
  993. $offset = ($page - 1) * $pageSize;
  994. $models = $query->offset($offset)->with('xhUser')->orderBy('visitTime desc')->limit($pageSize)->all();
  995. $page = new page($count, $page, $pageSize);
  996. $paging = $page->fpage();
  997. return $this->render('student', [
  998. 'models' => $models,
  999. 'pages' => $paging,
  1000. ]);
  1001. }
  1002. public function actionLevel()
  1003. {
  1004. $extend = xhMerchantExtendService::getByMerchantId($this->merchantId);
  1005. $gradeList = xhMerchantExtendService::getGradeList($extend);
  1006. return $this->render('level', ['extend' => $extend, 'gradeList' => $gradeList]);
  1007. }
  1008. /**
  1009. * 导入老客户
  1010. */
  1011. public function actionImportOldUser()
  1012. {
  1013. $request = Yii::$app->request->get();
  1014. $mobile = $request['mobile'];
  1015. $integral = $request['integral'];
  1016. $balance = $request['balance'];
  1017. $userName = isset($request['userName']) && !empty($request['userName']) ? $request['userName'] : $mobile;
  1018. $confirmPassword = $request['confirmPassword'];
  1019. $confirmMobile = $request['confirmMobile'];
  1020. if ($mobile != $confirmMobile) {
  1021. util::failInfo('二次手机号不致');
  1022. }
  1023. if (stringUtil::isMobieNumber($mobile) == false) {
  1024. util::failInfo('手机号填写错误');
  1025. }
  1026. $adminId = $this->adminId;
  1027. $admin = xhAdminService::getById($adminId);
  1028. $confirmPassword = $request['confirmPassword'];
  1029. if (md5($confirmPassword) != $admin['confirmPassword']) {
  1030. util::failInfo('确认密码有误');
  1031. }
  1032. if ($integral == $balance && $balance == 0) {
  1033. util::failInfo('请填写积分或余额');
  1034. }
  1035. $return = UserOldDataService::couldAdd($this->merchantId, $mobile);
  1036. if ($return['status'] == false) {
  1037. util::failInfo($return['msg']);
  1038. }
  1039. $integral = isset($integral) && $integral > 0 ? $integral : 0;
  1040. $balance = isset($balance) && $balance > 0 ? $balance : 0;
  1041. $data = ['mobile' => $mobile, 'integral' => $integral, 'balance' => $balance, 'createTime' => date("Y-m-d H:i:s"), 'userName' => $userName, 'merchantId' => $this->merchantId];
  1042. UserOldDataService::add($data);
  1043. util::successInfo();
  1044. }
  1045. public function actionBindMobile()
  1046. {
  1047. $userId = Yii::$app->request->get('userId');
  1048. $mobile = Yii::$app->request->get('mobile');
  1049. $info = xhUserService::getById($userId);
  1050. if ($info['merchantId'] != $this->merchantId) {
  1051. util::failInfo();
  1052. }
  1053. if ($info['subscribe'] != 1) {
  1054. util::failInfo('客户还没有关注公众号,无法绑定手机号');
  1055. }
  1056. if (!empty($info['mobile'])) {
  1057. util::failInfo('您已经有绑定手机号了');
  1058. }
  1059. $status = xhUserService::mobileNotUsed($mobile, $this->merchantId);
  1060. if ($status == false) {
  1061. util::failInfo('手机号已经被使用');
  1062. }
  1063. xhUserService::updateById($userId, ['mobile' => $mobile, 'isMember' => 1]);
  1064. xhUserAssetService::updateByUserId($userId, ['isMember' => 1]);
  1065. //绑定手机时判断是否有老客户资料
  1066. UserOldDataService::import($this->merchantId, $userId, $mobile);
  1067. util::successInfo('操作成功');
  1068. }
  1069. }