123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/5/2
- * Time: 上午10:09
- */
- namespace backend\controllers;
- use backend\base\CommonController;
- use backend\base\Help;
- use common\models\WxJc;
- use common\models\WxRand;
- use common\models\WxUserJc;
- use Yii;
- use common\models\WxUser;
- class WxController extends CommonController
- {
- /*
- * 首页-view
- * */
- public function actionHome()
- {
- return $this->render('home');
- }
- /*
- * 首页数据
- * */
- public function actionHomeform()
- {
- $model = new WxUser();
- $result = $model->getList(Yii::$app->request->post());
- if($result != null)
- {
- foreach ($result as &$val)
- {
- $val['create_at'] = date('Y-m-d H:i',$val['create_at']);
- }
- return Help::JsonData(0,'成功',$model->Total(Yii::$app->request->post()),$result);
- }
- return Help::JsonCode(Help::ERROR,'暂无数据');
- }
- /*
- * 添加页面
- * */
- public function actionCreate()
- {
- return $this->render('create');
- }
- /*
- * 添加数据
- * */
- public function actionCreateform()
- {
- $input = Yii::$app->request->post('data');
- $model = new WxUser();
- $model->name = $input['name'];
- $model->openid = 'a';
- $model->key = 'a';
- $Transaction = Yii::$app->db->beginTransaction();
- $result = $model->save();
- $jc = new WxUserJc();
- $jc->uid = $model->attributes['id'];
- $jc->jc = 0;
- $rand = WxRand::find()->andWhere(['state'=>1])->one();
- $rand->state = 2;
- $jc->rand = $rand->id;
- if($jc->save() == true && $result == true && $rand->save())
- {
- $Transaction->commit();
- return Help::JsonCode(Help::SUCCESS,'添加成功',['rand'=>$jc->rand]);
- }
- $Transaction->rollBack();
- return Help::JsonCode(Help::ERROR,'添加失败,请重新添加');
- }
- //===============奖次相关
- public function actionJchome()
- {
- return $this->render('jchome');
- }
- /*
- *
- * */
- public function actionJchomeform()
- {
- $model = new WxJc();
- $result = $model->getList(Yii::$app->request->post());
- $query = \common\models\WxUserJc::find();
- $groupJc = $query->andWhere(['<>','jc',0])->select(["count('js') as jcnum",'jc'])->groupBy('jc')->asArray()->all();
- $jc = array_column($groupJc,'jcnum','jc');
- if($result != null)
- {
- foreach ($result as &$val)
- {
- if(isset($jc[$val['id']]))
- {
- $val['state'] = '已抽';
- $val['total'] = $jc[$val['id']];
- }
- else
- {
- $val['state'] = '未抽';
- $val['total'] = 0;
- }
- $val['create_at'] = date('Y-m-d H:i',$val['create_at']);
- }
- return Help::JsonData(0,'成功',$model->Total(),$result);
- }
- return Help::JsonCode(Help::ERROR,'失败');
- }
- public function actionJccreate()
- {
- return $this->render('jccreate');
- }
- public function actionJccreateform()
- {
- $model = new WxJc();
- $input = Yii::$app->request->post();
- $one = $model::find()->andWhere(['name'=>$input['name']])->andWhere(['del'=>1])->one();
- if($one != null) return Help::JsonCode(Help::ERROR,'该奖次已存在');
- $model->name = $input['name'];
- if($model->save() == true) return Help::JsonCode(Help::SUCCESS,Yii::t('app','add_success'));
- return Help::JsonCode(Help::ERROR,Yii::t('app','add_error'));
- }
- public function actionJcedit()
- {
- $model = new WxJc();
- $input = Yii::$app->request->get();
- $row = $model->FindByOne($input['id']);
- return $this->render('jcedit',['model'=>$row]);
- }
- public function actionJceditform()
- {
- $model = new WxJc();
- $input = Yii::$app->request->post();
- $row = $model->FindByOne($input['id']);
- if($row != null)
- {
- $row->name = $input['name'];
- if($row->save() == true) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
- }
- return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_error'));
- }
- public function actionJcdel()
- {
- $model = new WxJc();
- $input = Yii::$app->request->post();
- $row = $model->FindByOne($input['id']);
- if($row != null)
- {
- $row->del = 2;
- if($row->save() == true) return Help::JsonCode(Help::SUCCESS,Yii::t('app','del_success'));
- }
- return Help::JsonCode(Help::SUCCESS,Yii::t('app','del_error'));
- }
- /*
- * 获奖人员名单
- * */
- public function actionAwardnamelist()
- {
- $input = Yii::$app->request->get();
- $rows = WxUserJc::find()->select(['pfg_wx_user.name','pfg_wx_user.photo','pfg_wx_user_jc.rand'])->andWhere(['pfg_wx_user_jc.jc'=>$input['id']])->leftJoin('pfg_wx_user','pfg_wx_user_jc.uid=pfg_wx_user.id')->asArray()->all();
- if($rows != null)
- {
- return $this->render('awardnamelist',['model'=>$rows]);
- }
- }
- /*
- * 清除奖次,重新抽奖
- * */
- public function actionJcclear()
- {
- $input = Yii::$app->request->post();
- $jcRows = WxUserJc::find()->andWhere(['jc'=>$input['id']])->asArray()->all();
- if($jcRows == null) return Help::JsonCode(Help::ERROR,'暂无该奖次记录');
- $beginTransaction = Yii::$app->db->beginTransaction();
- foreach ($jcRows as &$val)
- {
- $val['create_at'] = $_SERVER['REQUEST_TIME'];
- $val['update_at'] = $_SERVER['REQUEST_TIME'];
- $val['session_id'] = Yii::$app->session['user_info']['uid'];
- }
- $result = Yii::$app->db->createCommand()->batchInsert('pfg_wxjc_record',['jc','state','create_at','update_at','uid','rand','session_id'],$jcRows)->execute();
- $res = WxUserJc::updateAll(['jc'=>0,'state'=>1],['jc'=>$input['id']]);
- if($res > 0 && $result >0 )
- {
- $beginTransaction->commit();
- return Help::JsonCode(Help::SUCCESS,'操作成功');
- }
- $beginTransaction->rollBack();
- return Help::JsonCode(Help::ERROR,'操作失败');
- }
- //语录
- public function actionYhome()
- {
- return $this->render('yhome');
- }
- public function actionYhomeform()
- {
- $model = new \common\models\WxJt();
- $rows = $model->getList(Yii::$app->request->post());
- if($rows != null)
- {
- return Help::JsonData(0,'成功',$model->Total(),$rows);
- }
- }
- public function actionYcreate()
- {
- return $this->render('ycreate');
- }
- public function actionYcreateform()
- {
- $model = new \common\models\WxJt();
- $input = Yii::$app->request->post('data');
- $model->text = $input['name'];
- if($model->save()) return Help::JsonCode(Help::SUCCESS,'添加成功');
- return Help::JsonCode(Help::ERROR,'添加失败');
- }
- public function actionYedit()
- {
- $row = \common\models\WxJt::findOne(Yii::$app->request->get('id'));
- if($row != null)
- {
- return $this->render('yedit',['model'=>$row]);
- }
- }
- public function actionYeditform()
- {
- $input = Yii::$app->request->post('data');
- $row = \common\models\WxJt::findOne($input['id']);
- if($row != null)
- {
- $row->text = $input['name'];
- if($row->save()) return Help::JsonCode(Help::SUCCESS,'操作成功');
- return Help::JsonCode(Help::ERROR,'操作失败');
- }
- }
- public function actionYdel()
- {
- $row = \common\models\WxJt::findOne(Yii::$app->request->post('id'));
- if($row != null)
- {
- if($row->delete() == true) return Help::JsonCode(Help::SUCCESS,'操作成功');
- return Help::JsonCode(Help::ERROR,'操作失败');
- }
- }
- }
|