1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace app\store\model\coupon;
- use app\common\library\helper;
- use app\common\model\coupon\CouponRedeemCodes as RedeemCodesModel;
- /**
- * 优惠券生成兑换码记录模型
- * @package app\common\model
- */
- class CouponRedeemCodes extends RedeemCodesModel
- {
- /**
- * 批量添加兑换码
- * @param $data
- * @return bool
- * @throws \Exception
- */
- public function addBatch($data){
- $m = new self();
- $m->saveAll($data);
- return true;
- }
- /**
- * 校验码是否用过
- * @param $code
- * @return bool
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function checkExistedCode($code){
- $m = new self();
- if ($m->where('redeem_code',$code)->find()){
- return true;
- }
- return false;
- }
- public function getAllList($genId){
- return $this->alias('rc')
- ->leftJoin('coupon cp', 'rc.coupon_id = cp.coupon_id')
- ->leftJoin('coupon_gen_redeem_codes gc', 'rc.coupon_gen_redeem_codes_id = gc.id')
- ->where('coupon_gen_redeem_codes_id',$genId)
- ->field('rc.id,rc.redeem_code,rc.coupon_id,gc.give_channel,cp.name,cp.coupon_type')->paginate(15);
- }
- public function redeemCodesExport($param,$all=false){
- $ids = $param['ids'];
- $data['header'] = ['序号','优惠券名称','兑换码', '发放渠道'];
- $data['filename'] = '优惠券兑换码导出';
- $data['data'] = [];
- $items = $this->alias('rc')
- ->leftJoin('coupon cp', 'rc.coupon_id = cp.coupon_id')
- ->leftJoin('coupon_gen_redeem_codes gc', 'rc.coupon_gen_redeem_codes_id = gc.id');
- if ($all == true){
- $items = $items->where('rc.coupon_gen_redeem_codes_id',$param['id']);
- }
- if (count($ids) > 0){
- $items = $items->whereIn('rc.id',$ids);
- }
- $items = $items->field('(rc.id+70000000) as id,cp.name,rc.redeem_code,gc.give_channel')->select()->toArray();
- //$items = [];
- $data['data'] = $items;
- return $data;
- }
- }
|