UsersignupController.php 12 KB

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