public function coupons_set() { $itemid = $this->_get('itemid', 'intval'); $coupon_type = $this->_get('coupon_type', 'trim'); $attr = $this->_get('attr', 'trim'); $type = $this->_get('cardType', 'trim'); $info = M('Member_card_coupon')->where(array('token' => $this->token, 'id' => $itemid))->find(); if ($coupon_type == 'weixin') { $company = M('Company')->where(array('token' => $this->token, 'location_id' => array('neq', 0)))->select(); if (empty($company)) { $this->error('添加微信卡券,请先设置并导入门店信息', U('Company/index', array('token' => $this->token))); } } if (IS_POST) { if (D('Member_card_coupon')->create()) { if ($info) { if ($this->wxuser['wx_coupons'] && $info['is_weixin'] == 1) { $this->error('非法修改,请重新操作', U('Member_card/coupons')); } if (D('Member_card_coupon')->where(array('token' => $this->token, 'id' => $this->_post('id', 'intval')))->save()) { $this->success('修改成功', U('Member_card/coupons', array('token' => $this->token, 'itemid' => $this->_post('id', 'intval')))); } else { $this->error('修改失败'); } } else { $id = D('Member_card_coupon')->add(); if ($id) { if ($coupon_type == 'weixin') { $coupons = new WechatCoupons($this->wxuser); $res = $coupons->createCard($id); if ($res['errcode'] == 0) { D('Member_card_coupon')->where(array('token' => $this->token, 'id' => $id))->save(array('is_weixin' => 1, 'card_id' => $res['card_id'])); $this->success('添加成功', U('Member_card/coupons')); } else { $err = '添加失败:' . $res['errmsg'] . ''; D('Member_card_coupon')->where(array('token' => $this->token, 'id' => $id))->delete(); $this->error($err); } } else { $this->success('添加成功', U('Member_card/coupons')); } } else { $this->error('添加失败'); } } } else { $this->error(D('Member_card_coupon')->getError()); } } else { $allcard = M('Member_card_set')->where(array('token' => $this->token))->order('id ASC')->select(); $companywhere = array('token' => $this->token); if ($coupon_type == 'weixin') { $companywhere['location_id'] = array('neq', 0); } $company = M('Company')->where($companywhere)->order('isbranch asc,id desc')->select(); if ($this->wxuser['wx_coupons']) { $coupons = new WechatCoupons($this->wxuser); $color = $coupons->getColor(); $this->assign('color', $color); } $now = time(); $this->assign('vip', $info); $this->assign('statdate', $now); $this->assign('enddate', strtotime('+1 month', $now)); $this->assign('attr', $attr); $this->assign('type', $type); $this->assign('coupon_type', $coupon_type); $this->assign('company', $company); $this->assign('allcard', $allcard); $this->display(); } }