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; } }