123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?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, 0, false );
- $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, 0, false );
- $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));
- $criteria = new EMongoCriteria($pageParams);
- if ($status != 100 ) {
- $criteria->status('==',$status);
- }
- if ($search) {
- $criteria->addCond('title','or',new MongoRegex('/' . $search . '/'));
- }
- $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;
- $coupon->save();
- CommonFn::requestAjax(true,'保存成功');exit;
- }
- public function actionAdd()
- {
- $num = (int)Yii::app()->request->getParam('num','');
- $gift_id = Yii::app()->request->getParam('gift_id','');
- $channel = Yii::app()->request->getParam('bus_id','');
- $expire_time = Yii::app()->request->getParam('expire_time_str','');
- if (!$num ||!$channel || !$gift_id || !$expire_time) {
- CommonFn::requestAjax(false,'请填写完整信息');exit;
- }
- $gift = Gift::get(new MongoId($gift_id));
- if (empty($gift)) {
- CommonFn::requestAjax(false,'礼包不存在');exit;
- }
- for($i=0; $i<$num; $i++) {
- $coupon = new JCoupon();
- $coupon->gift_id = $gift_id;
- $flag = true;
- while($flag) {
- $pwd = $coupon->generateRandomString(8);
- $tmp = JCoupon::getByPwd($pwd);
- if (empty(count($tmp))){
- $flag = false;
- }
- }
- $coupon->pwd = $pwd;
- $coupon->channel = $channel;
- $coupon->status = 0;
- $coupon->expire_time = $expire_time;
- $coupon->save();
- }
- CommonFn::requestAjax(true,'生成成功');exit;
- }
- }
|