saveAll($data); return true; } public function getActiveTimeAttr($value){ return $value?date('Y-m-d H:i:s',$value):''; } public function getAllList($params){ $filter = $this->getQueryFilter($params); $m = $this->alias('gc') ->leftJoin('gen_real_rice_cards rg','gc.gen_real_rice_card_id=rg.id') ->leftJoin('rice_card rc','gc.rice_card_id=rc.id') ->where('gc.gen_real_rice_card_id',$params['genId']); if (count($filter)){ $m = $m->where($filter); } //调试模式开启兑换码 if (env('APP_DEBUG')){ $fields = 'gc.id,gc.gen_real_rice_card_id,gc.rice_card_id,gc.card_number,gc.redeem_code,gc.been_exported,gc.been_active,gc.active_time,gc.frozen_status,gc.create_time,rc.type,rc.name,if(rc.expire_day>0,FROM_UNIXTIME(gc.create_time + (rc.expire_day-1)*86400,"%Y-%m-%d 23:59:59"),"永久有效") as expire_time,rc.describe,rc.card_price,rg.sale_channel'; }else{ $fields = 'gc.id,gc.gen_real_rice_card_id,gc.rice_card_id,gc.card_number,concat(left(gc.redeem_code,2),"****",right(gc.redeem_code,2)) as redeem_code,gc.been_exported,gc.been_active,gc.active_time,gc.frozen_status,gc.create_time,rc.type,rc.name,if(rc.expire_day>0,FROM_UNIXTIME(gc.create_time + (rc.expire_day-1)*86400,"%Y-%m-%d 23:59:59"),"永久有效") as expire_time,rc.describe,rc.card_price,rg.sale_channel'; } //'gc.id,gc.gen_real_rice_card_id,gc.rice_card_id,gc.card_number,gc.redeem_code,concat(left(gc.redeem_code,2),"****",right(gc.redeem_code,2)) as mi_code,gc.been_exported,gc.been_active,gc.active_time,gc.frozen_status,gc.create_time,rc.type,rc.name,FROM_UNIXTIME(gc.create_time + rc.expire_day*86400) as expire_time,rc.describe,rc.card_price,rg.sale_channel' return $m->field($fields) ->order('id','asc')->paginate(15); } //查询 public function getQueryFilter($param){ $filter = []; if(isset($param['name']) && $param['name']){ $filter[] = ['rc.name','like','%'.$param['name'].'%']; } if(isset($param['type']) && $param['type'] > 0){ $filter[] = ['rc.type','=',$param['type']]; } if(isset($param['export']) && $param['export'] >= 0){ $filter[] = ['gc.been_exported','=',$param['export']]; } // 创建时间 if (!empty($param['createTime'])) { $times = between_time($param['createTime']); $filter[] = ['gc.create_time', '>=', $times['start_time']]; $filter[] = ['gc.create_time', '<', $times['end_time'] + 86400]; } return $filter; } public function updateFrozenStatus($param){ $this->where('id',$param['id'])->update(['frozen_status'=>$param['status']]); return true; } public function updateBeenExported($param){ $this->whereIn('id',$param['ids'])->update(['been_exported'=>1]); return true; } public function redeemCodesExport($param,$all=false){ $ids = $param['ids']; $data['header'] = ['序号','卡号','米卡名称','米卡售价', '米卡类型','截止日期','激活码','销售渠道','生成时间','是否导出','当前状态','激活时间']; $data['filename'] = '实体实物兑换卡'; $data['data'] = []; $m = $this->alias('gc') ->leftJoin('gen_real_rice_cards rg','gc.gen_real_rice_card_id=rg.id') ->leftJoin('rice_card rc','gc.rice_card_id=rc.id'); if ($all == true){ $m = $m->where('gc.gen_real_rice_card_id',$param['id']); } if (count($ids) > 0){ $m = $m->whereIn('gc.id',$ids); } //->where('gc.gen_real_rice_card_id',$param['genId']); /* if (count($filter)){ $m = $m->where($filter); }*/ //$lists = $m->field('gc.id,gc.gen_real_rice_card_id,gc.rice_card_id,gc.card_number,concat(left(gc.redeem_code,2),"****",right(gc.redeem_code,2)) as redeem_code,gc.been_exported,gc.been_active,gc.active_time,gc.frozen_status,gc.create_time,rc.type as types,rc.name as cname,rc.expire_day,rc.card_price,rg.sale_channel') $lists = $m->field('gc.id,gc.gen_real_rice_card_id,gc.rice_card_id,gc.card_number,gc.redeem_code,gc.been_exported,gc.been_active,gc.active_time,gc.frozen_status,gc.create_time,rc.type as types,rc.name as cname,rc.expire_day,rc.card_price,rg.sale_channel') ->order('id','asc')->select(); $items = []; foreach ($lists as $key=>$list){ $temp = []; $temp['id'] = $key+1;//$list->id; $temp['card_number'] = $list->card_number; $temp['name'] = $list->cname; $temp['card_price'] = $list->card_price; $temp['type'] = RiceCard::TYPE[$list->types]; $temp['expire_day'] = $list->expire_day>0?date('Y-m-d 23:59:59',strtotime($list->create_time) + ($list->expire_day-1)*86400):'永久有效'; $temp['redeem_code'] = $list->redeem_code; $temp['sale_channel'] = $list->sale_channel; $temp['create_time'] = $list->create_time; $temp['been_exported'] = '是'; $temp['status'] = $list->been_active?'已激活':($list->frozen_status?'已冻结':'未激活'); $temp['active_time'] = $list->active_time; //$temp['active_time'] = $list->active_time?date('Y-m-d H:i:s',$list->active_time):'-'; $items[] = $temp; } $data['data'] = $items; return $data; } }