UsersignupController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/2/26/026
  6. * Time: 15:06
  7. * 前端用户报名
  8. */
  9. namespace backend\controllers;
  10. use backend\base\CommonController;
  11. use backend\base\Help;
  12. use common\api\EnrollServer;
  13. use common\event\Event;
  14. use common\models\Email;
  15. use common\models\HttpRecord;
  16. use Yii;
  17. use common\models\Enroll;
  18. use common\models\EnrollSource;
  19. use common\models\AstrictPhone;
  20. use common\enums\EmailEnum;
  21. class UsersignupController extends CommonController
  22. {
  23. public function actionHome()
  24. {
  25. $model = new EnrollSource();
  26. $source_1 = $model->getList(['type' => 1], ['source_id', 'name', 'type']);
  27. $source_2 = $model->getList(['type' => 2], ['source_id', 'name', 'type']);
  28. return $this->render('home', ['source' => $source_1, 'source_2' => $source_2]);
  29. }
  30. public function actionHomeform()
  31. {
  32. $model = new Enroll();
  33. $rows = $model->getList(Yii::$app->request->post());
  34. if (!empty($rows['data'])) {
  35. $m = (new \common\models\EnrollSource())->TypeColumn(1);
  36. $p = (new \common\models\EnrollSource())->TypeColumn(2);
  37. foreach ($rows['data'] as &$val) {
  38. if (isset($val['mobile'])&&!empty($val['mobile'])){
  39. $val['mobile'] = Help::HideTel($val['mobile']);
  40. }
  41. if (isset($p[$val['source']]) && $val['equipment'] == 2) {
  42. $val['source'] = $p[$val['source']];
  43. }
  44. if (isset($m[$val['source']]) && $val['equipment'] == 1) {
  45. $val['source'] = $m[$val['source']];
  46. }
  47. $val['equipment'] = $model->equipmentArr[$val['equipment']];
  48. $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
  49. $val['state'] = $model->stateArr[$val['state']];
  50. if (\common\models\TestNumber::find()->andWhere(['number' => $val['mobile'], 'is_show' => 1])->asArray()->one()) {
  51. $val['state'] = '测试号码不发送';
  52. }
  53. $email = Email::find()->select(['email'])->andWhere(['del' => 1])->andWhere(['city' => $val['house_city']])->asArray()->one();
  54. $val['email'] = $email['email'];
  55. }
  56. return Help::JsonData(0, '成功', $rows['total'], $rows['data']);
  57. }
  58. return Help::JsonCode(Help::ERROR, '暂无数据');
  59. }
  60. /*
  61. * 用户详情
  62. * */
  63. public function actionUserdetails()
  64. {
  65. $model = new Enroll();
  66. $model->id = Yii::$app->request->get('id');
  67. $result = $model->FindByIds();
  68. if (!empty($result)) {
  69. $m = (new \common\models\EnrollSource())->TypeColumn(1);
  70. $p = (new \common\models\EnrollSource())->TypeColumn(2);
  71. if (isset($p[$result['source']]) && $result['equipment'] == 2) {
  72. $result['source'] = $p[$result['source']];
  73. }
  74. if (isset($result['mobile'])&&!empty($result['mobile'])){
  75. $result['mobile'] = Help::HideTel($result['mobile']);
  76. }
  77. if (isset($m[$result['source']]) && $result['equipment'] == 1) {
  78. $result['source'] = $m[$result['source']];
  79. }
  80. $result['create_at'] = date('Y-m-d H:i', $result['create_at']);
  81. $result['equipment'] = $model->equipmentArr[$result['equipment']];
  82. $result['state'] = $model->stateArr[$result['state']];
  83. return $this->render('userdetails', ['model' => $result]);
  84. }
  85. }
  86. /*
  87. * 删除
  88. * */
  89. public function actionSignupdel()
  90. {
  91. $model = new Enroll();
  92. $row = $model->FindById(Yii::$app->request->post('id'));
  93. if (!empty($row)) {
  94. $row->del = 2;
  95. if ($row->save()) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  96. }
  97. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'));
  98. }
  99. //用户来源@2019.8.17
  100. public function actionUserform()
  101. {
  102. $get = Yii::$app->request->get();
  103. $result = Enroll::findOne($get['id']);
  104. if ($result != null) {
  105. $result['create_at'] = date('Y-m-d', $result['create_at']);
  106. $query = (new HttpRecord())->GetList($result);
  107. return $this->render('userform', ['model' => $query, 'row' => $result]);
  108. }
  109. }
  110. /*
  111. * 报名栏目来源
  112. */
  113. public function actionLabel()
  114. {
  115. return $this->render('label');
  116. }
  117. public function actionLabelform()
  118. {
  119. $model = new EnrollSource();
  120. $row = $model->getList(Yii::$app->request->post());
  121. $m = new Enroll();
  122. if (!empty($row)) {
  123. foreach ($row as &$val) {
  124. $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
  125. $val['type'] = $m->equipmentArr[$val['type']];
  126. }
  127. return Help::JsonData(0, '成功', $model->getListTotal(Yii::$app->request->post()), $row);
  128. }
  129. return Help::JsonCode(Help::ERROR, Yii::t('app', 'get_error'), []);
  130. }
  131. public function actionLabeladd()
  132. {
  133. $model = new Enroll();
  134. return $this->render('labeladd', ['source' => $model->equipmentArr]);
  135. }
  136. public function actionLabeladdform()
  137. {
  138. $input = Yii::$app->request->post('data');
  139. $one = EnrollSource::find()->andWhere(['type' => $input['type']])->orderBy(['create_at' => SORT_DESC])->asArray()->one();
  140. if (!empty($one)) {
  141. $input['source_id'] = ++$one['source_id'];
  142. } else {
  143. $input['source_id'] = 0;
  144. }
  145. $model = new EnrollSource();
  146. $model->scenario = 'add';
  147. $input['uid'] = Yii::$app->session['user_info']['uid'];
  148. if ($model->load($input, '') && $model->save()) {
  149. return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_success'));
  150. }
  151. return Help::JsonCode(Help::ERROR, Yii::t('app', 'add_error'), $model->errors);
  152. }
  153. public function actionLabeledit()
  154. {
  155. $model = new Enroll();
  156. $m = new EnrollSource();
  157. $row = $m->FindById(Yii::$app->request->get('id'));
  158. if (!empty($row)) {
  159. return $this->render('labeledit', ['source' => $model->equipmentArr, 'model' => $row]);
  160. }
  161. }
  162. public function actionLabeleditform()
  163. {
  164. $m = new EnrollSource();
  165. $input = Yii::$app->request->post('data');
  166. $row = $m->FindById($input['id']);
  167. if ($row->load($input, '') && $row->save()) {
  168. return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  169. }
  170. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'));
  171. }
  172. /*邮箱发送*/
  173. public function actionEmailsend()
  174. {
  175. $EmailModel = new \common\models\Enroll();
  176. $result = $EmailModel->getList(Yii::$app->request->post());
  177. try {
  178. foreach ($result['data'] as $k => $v) {
  179. $emailData['username'] = $v['name'];
  180. $emailData['mobile'] = $v['mobile'];
  181. $emailData['housename'] = $v['house_name'];
  182. $emailData['city_name'] = $v['city_name'];
  183. $emailData['id'] = $v['id'];
  184. //发送邮件
  185. (new \common\service\common\MailerService())->send($v['send_email'], $emailData, EmailEnum::SITEFORM);
  186. }
  187. return Help::JsonCode(Help::SUCCESS, '邮件发送中');
  188. } catch (\Exception $e) {
  189. return Help::JsonCode(Help::ERROR, $e->getMessage());
  190. }
  191. }
  192. public function actionStatistica()
  193. {
  194. return $this->render('statistica');
  195. }
  196. public function actionStatisticaform()
  197. {
  198. $input = Yii::$app->request->post();
  199. if (!empty($input['date_month'])) {
  200. $start_end_time = \common\Helps\Time::getthemonth($input['date_month']);
  201. if (!empty($start_end_time)) {
  202. $startTime = strtotime($start_end_time[0] . ' 00:00:00');
  203. $endTime = strtotime($start_end_time[1] . ' 23:59:59');
  204. }
  205. } else {
  206. $start_end_time = \common\Helps\Time::getthemonth(date('Y-m'));
  207. if (!empty($start_end_time)) {
  208. $startTime = strtotime($start_end_time[0] . ' 00:00:00');
  209. $endTime = strtotime($start_end_time[1] . ' 23:59:59');
  210. }
  211. }
  212. $query = \common\models\Enroll::find();
  213. $rows = $query->select(['COUNT(mobile) as mobile_count', "FROM_UNIXTIME(create_at,'%Y-%m-%d') as addtime", 'equipment'])->andWhere(['del' => 1])
  214. ->andWhere(['>=', 'create_at', $startTime])
  215. ->andWhere(['<=', 'create_at', $endTime])
  216. ->groupBy(['addtime', 'mobile'])->asArray()->all();
  217. if ($rows) {
  218. $arr = [];
  219. $date_column = array_column($rows, 'addtime');
  220. foreach ($rows as $val) {
  221. if (in_array($val['addtime'], $date_column)) {
  222. // if(empty($arr[$val['addtime']]['dim_count']))
  223. // {
  224. // $arr[$val['addtime']]['dim_count'] = 0;
  225. // }
  226. //
  227. // if(empty($arr[$val['addtime']]['precise']))
  228. // {
  229. // $arr[$val['addtime']]['precise'] = 0;
  230. // }
  231. $arr[$val['addtime']]['time'] = $val['addtime'];
  232. $arr[$val['addtime']]['dim_count'] += $val['mobile_count'];
  233. $arr[$val['addtime']]['precise'] += 1;
  234. switch ($val['equipment']) {
  235. case 1:
  236. $arr[$val['addtime']]['m'] += 1;
  237. break;
  238. case 2:
  239. $arr[$val['addtime']]['pc'] += 1;
  240. break;
  241. }
  242. }
  243. }
  244. return Help::JsonData(0, '成功', 0, array_values($arr));
  245. }
  246. return Help::JsonCode(Help::ERROR, '暂无数据');
  247. }
  248. //$EmailModel = new \common\models\Enroll();
  249. // $result=$EmailModel->getList(Yii::$app->request->post());
  250. // $en = new \common\api\EnrollServer();
  251. // $arr = [];
  252. // foreach($result as $k=>$v)
  253. // {
  254. // if(!empty($v['name']))
  255. // {
  256. // $en->username = $v['name'];
  257. // }
  258. // $en->mobile = $v['mobile'];
  259. // $en->housename = $v['house_name'];
  260. // $en->city = $v['city_name'];
  261. // //发送邮件
  262. // $event = new \common\event\Event();
  263. // $arr['email'] = $v['send_email'];
  264. // $arr['title'] = Yii::t('app','enter_email');
  265. // $arr['content'] = $en->TemplateOne();
  266. // $arr['id'] = $v['id'];
  267. // $event->SendEmail($arr);
  268. // $EmailModel::updateAll(['state'=>2],['id'=>$v['id']]);
  269. // }
  270. // return Help::JsonCode(Help::SUCCESS,'发送成功');
  271. /*
  272. * 2020.7.27 lyy 报名限制
  273. *
  274. * */
  275. public function actionAstrict()
  276. {
  277. return $this->render('astrict');
  278. }
  279. public function actionAstrictform()
  280. {
  281. $input = Yii::$app->request->post();
  282. $rows = new AstrictPhone();
  283. $dataInfo = $rows->getList($input);
  284. $count = $rows->getTotal();
  285. foreach ($dataInfo as &$val) {
  286. $val['create_at'] = date('Y-m-d H:i:s', $val['create_at']);
  287. }
  288. return Help::JsonData(0, '成功', $count, $dataInfo);
  289. }
  290. public function actionAstrictadd()
  291. {
  292. return $this->render('astrictadd');
  293. }
  294. public function actionAstrictaddto()
  295. {
  296. $input = Yii::$app->request->post('data');
  297. $rows = new AstrictPhone();
  298. $rows->load($input);
  299. if (!$rows->validate()) return Help::JsonCode(Help::ERROR, '提交失败', $rows->errors);
  300. $rows->mobile = $input['mobile'];
  301. $rows->astrict_msg = $input['astrict_msg'];
  302. if ($rows->save()) return Help::JsonCode(Help::SUCCESS, '添加成功');
  303. return Help::JsonCode(Help::SUCCESS, '添加失败');
  304. }
  305. public function actionAstrictdel()
  306. {
  307. $id = Yii::$app->request->post('id');
  308. $rows = AstrictPhone::findOne($id);
  309. if ($rows->delete()) return Help::JsonCode(Help::SUCCESS, '删除成功');
  310. return Help::JsonCode(Help::SUCCESS, '删除失败');
  311. }
  312. public function actionAstrictstate()
  313. {
  314. $input = Yii::$app->request->post();
  315. $rows = AstrictPhone::findOne($input['id']);
  316. $rows->state = $input['state'];
  317. if ($rows->update(false)) return Help::JsonCode(Help::SUCCESS, '设置成功');
  318. return Help::JsonCode(Help::SUCCESS, '设置失败');
  319. }
  320. }