123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <?php
- /**
- * Created by north.Deng's MAC
- * User: north.Deng
- * Date: 2018/2/28
- * Time: 下午12:30
- * description :
- */
- class JCouponController extends AdminController
- {
- public function actionIndex()
- {
- $status = CommonFn::getComboboxData(JCoupon::$status_options, 100, true, 100);
- $gifts = Gift::model()->findAll();
- $tmp =[];
- foreach ($gifts as $gift) {
- $tmp[] = array('name' => $gift->title,'id' => (string)$gift->_id);
- }
- $tmp = CommonFn::getComboboxData($tmp, 100, true, 100 );
- $c = new EMongoCriteria();
- $c->type('==',1);
- $bs = Business::model()->findAll($c);
- $tmp1 =[];
- foreach ($bs as $gift) {
- $tmp1[] = array('name' => $gift->source,'id' => (string)$gift->_id);
- }
- $tmp1 = CommonFn::getComboboxData($tmp1, 100, true, 100);
- $this->render('index',array(
- 'status' => $status,
- 'gifts' => $tmp,
- 'bus' => $tmp1
- ));
- }
- public function actionList()
- {
- $pageParams = CommonFn::getPageParams();
- $search = Yii::app()->request->getParam('search', '');
- $status = intval(Yii::app()->request->getParam('status', 100));
- $gift_num = intval(Yii::app()->request->getParam('gift', 100));
- $criteria = new EMongoCriteria($pageParams);
- if ($status != 100 ) {
- $criteria->status('==',$status);
- }
- if ($gift_num != 100 ) {
- $gifts = Gift::model()->findAll();
- $tmp =[];
- foreach ($gifts as $gift) {
- $tmp[] = array('name' => $gift->title,'id' => (string)$gift->_id);
- }
- $criteria->gift_id('==',$tmp[$gift_num]['id']);
- }
- if ($search) {
- $criteria->addCond('coupon_coding','or',new MongoRegex('/' . $search . '/'));
- }
- $criteria->sort('coupon_coding',EMongoCriteria::SORT_ASC);
- $cursor = JCoupon::model()->findAll($criteria);
- $rows = CommonFn::getRowsFromCursor($cursor);
- $parsedRows = JCoupon::model()->parse($rows);
- $total = $cursor->count();
- echo CommonFn::composeDatagridData($parsedRows, $total);
- }
- public function actionEdit()
- {
- $id = Yii::app()->request->getParam('id','');
- $status = (int)Yii::app()->request->getParam('status',0);
- if (!CommonFn::isMongoId($id)) {
- CommonFn::requestAjax(false,'id错误');exit;
- }
- $coupon = JCoupon::get(new MongoId($id));
- $coupon->status = $status;
- if (empty($coupon->add_time)) {
- $coupon->add_time = time();
- }
- $coupon->save();
- CommonFn::requestAjax(true,'保存成功');exit;
- }
- public function actionAdd()
- {
- $num = (int)Yii::app()->request->getParam('num','');
- // $coding_num = (int)Yii::app()->request->getParam('coding_num','');
- $gift_id = Yii::app()->request->getParam('gift_id','');
- $gift = Yii::app()->request->getParam('gift','');
- $channel = Yii::app()->request->getParam('bus_id','');
- $bus = (int)Yii::app()->request->getParam('bus','');
- $expire_time = Yii::app()->request->getParam('expire_time_str','');
- if ($bus == 100 || !$num ||!$channel || !$gift_id || !$expire_time) {
- CommonFn::requestAjax(false,'请填写完整信息');exit;
- }
- if ($gift == 100) {
- CommonFn::requestAjax(false,'请选择礼包');exit;
- }
- $gift = Gift::get(new MongoId($gift_id));
- if (empty($gift)) {
- CommonFn::requestAjax(false,'礼包不存在');exit;
- }
- // if ($coding_num > 100000) {
- // CommonFn::requestAjax(false,'起始值不能超过100000');exit;
- // }
- /*$c = new EMongoCriteria();
- $c->coding_num('==',$coding_num);
- $j = JCoupon::model()->findAll($c);
- if (count($j) > 0) {
- CommonFn::requestAjax(false,'起始值重复');exit;
- }*/
- $total = 10000;
- for($i=0; $i<$num; $i++) {
- $coupon = new JCoupon();
- $coupon->gift_id = $gift_id;
- // $tmp1 = $coding_num + 100000;
- // $coupon->coding_num = date('d').substr($tmp1,1);
- $flag = true;
- while($flag) {
- $pwd = $coupon->generateRandomString(8);
- $tmp = JCoupon::getByPwd($pwd);
- if (empty(count($tmp))){
- $flag = false;
- }
- }
- $total++;
- $coupon->pwd = $pwd;
- $coupon->coupon_coding = $gift->gift_num.substr(date('Y'),2).date('md').substr($total,1);
- $coupon->channel = $channel;
- $coupon->status = 0;
- $coupon->expire_time = $expire_time;
- $coupon->created_at = time();
- // if (substr($coupon->coding_num,5) == substr($coupon->coupon_coding,-3)) {
- // CommonFn::requestAjax(false,'起始值重复');exit;
- // }
- $coupon->add_time = time();
- $coupon->save();
- // $coding_num++;
- }
- CommonFn::requestAjax(true,'生成成功');exit;
- }
- public function actionOutputExcel()
- {
- $start_num = Yii::app()->request->getParam('start_num','');
- // $total = (int)Yii::app()->request->getParam('total','');
- $criteria = new EMongoCriteria();
- $criteria->addCond('coupon_coding','or',new MongoRegex('/' . $start_num . '/'));
- // $num = (int)'1'.substr($start_num,2,6);
- // for ($i=0;$i<$total;$i++) {
- // $criteria = new EMongoCriteria();
- // $day = substr($start_num,0,2);
- //
- // $tmp = $day.substr($num,1,6);
- // $criteria->coding_num('==',$tmp);
- // $coupon = JCoupon::model()->find($criteria);
- // if (!empty($coupon)) {
- // $data[] = [
- // 'coupon_coding' => $coupon->coupon_coding,
- // 'coding_num' => $coupon->coding_num,
- // 'pwd_str' => $coupon->pwd,
- // ];
- // }
- // $num++;
- //
- // }
- $cursor = JCoupon::model()->findAll($criteria);
- $rows = CommonFn::getRowsFromCursor($cursor);
- $parsedRows = JCoupon::model()->parse($rows);
- $res=Service::factory('JCouponService')->push($parsedRows);
- }
- public function actionOutputExcel1()
- {
- $start_num = Yii::app()->request->getParam('start_num','');
- $total = Yii::app()->request->getParam('num','');
- $id = Yii::app()->request->getParam('id','');
- $criteria = new EMongoCriteria();
- $num = substr($start_num,0,strlen($start_num) - 4);
- for ($i=0;$i<$total;$i++) {
- $criteria = new EMongoCriteria();
- $day = intval("1".substr($start_num,-4,4)) +$i;
- $tmp = $num.substr($day,1,strlen($day) - 1);
- $criteria->coupon_coding('==',$tmp);
- $coupon = JCoupon::model()->find($criteria);
- if (!empty($coupon)) {
- $coupon->channel = $id;
- $coupon->save();
- }
- }
- CommonFn::requestAjax(true,'修改成功');exit;
- }
- }
|