title = '兑换码管理'; $goods_id = input('id',0); $code = input('code',''); $status = input('status',0); $this->goods_id = $goods_id; $query = $this->_query($this->table)->alias('c') ->field('c.*,m.name as user_name') ->join('store_member m','m.id=c.user_id','LEFT') ->where('c.goods_id',$goods_id); if($code) $query->where('c.code',$code); if($status) $query->where('c.status',$status); $query->order('status asc , id desc')->page(); } /** * 数据列表处理 * @auth true * @menu true * @param array $data * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ protected function _index_page_filter(&$data) { foreach ($data as $k=>&$v){ } } /** * 添加兑换码 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function add() { $this->title = '添加兑换码'; $goods_id = input('goods_id',0); $this->goods_id = $goods_id; $this->_form($this->table, 'form'); } /** * 表单数据处理 * @auth true * @menu true * @param array $data */ protected function _form_filter(&$data) { if($this->request->post() && $this->request->action() == 'add'){ $code_arr=[]; for($i=0;$i< $data['num'];$i++){ $code_str = $this->getRegisterCode($data['goods_id']); $code_arr[] = [ 'code' => $code_str, 'goods_id' => $data['goods_id'], ]; } Db::table('goods_code')->insertAll($code_arr); $this->success('添加成功!'); } } /** * @auth true * @menu true * 兑换码下架 */ public function del() { $this->_delete($this->table); } public function getRegisterCode($goods_id) { $length = 13; $base_code = explode(',',"A,B,C,D,E,F,G,H,J,K,L,0,1,2,3,4,5,6,7,8,9,M,N,P,Q,R,S,T,U,V,W,X,Y,Z"); $id_length = strlen($goods_id); $code_key = array_rand($base_code, $length - $id_length); $code_str = ''; array_map(function ($val)use (&$code_str,$base_code){ $code_str .=$base_code[$val] ; },$code_key); return $code_str.$goods_id; } }