UID, ]; $category_model = new FireProductCategory(); $dataList = $category_model->getAllData($where, '*', 'sort desc'); View::assign('dataList', $dataList); return View::fetch(); } /** * 添加分类 */ public function categoryAdd() { $category_model = new FireProductCategory(); if (request()->isPost()) { $data = input('post.'); $data['uid'] = UID; $res = $category_model->dataUpdate($data); if (!$res) { return sendErrorMessage(); } return sendSuccessMessage(); } else { $id = input('param.id', 0); $data = $category_model->getOneData(['id' => $id]); View::assign('data', $data); return View::fetch('categoryadd'); } } /** * 修改分类 */ public function categoryUpdate() { return $this->categoryadd(); } /** * 材料列表 * @return string */ public function product() { $search = input('get.'); autoSearch(['time', 'keyword','supply_name','supply_phone', 'category_id', 'status'], $search); $product_model = new FireProduct(); $category_model = new FireProductCategory(); $where = [['uid','=',UID],['status','<>',1]]; $hasWhere = []; if ($search['time']) { $time = explode('-', $search['time']); $where[] = ['create_time','between time', [$time[0], $time[1]]]; } if ($search['keyword']) { $where[] = ['name','like', '%' . $search['keyword'] . '%']; } if ($search['supply_name']) { $hasWhere[] = ['company_name','like', '%' . $search['supply_name'] . '%']; } if ($search['supply_phone']) { $hasWhere[] = ['mobile_phone','like', '%' . $search['supply_phone'] . '%']; } if ($search['status'] !== '') { $where []= ['status','=',$search['status']]; } if ($search['category_id'] != '') { $where[] = ['category_id','=',$search['category_id']]; } $where = $product_model->whereChange($where); session('where',$where); session('hasWhere',$hasWhere); $dataList = $product_model::hasWhere('productSupply',$hasWhere)->with(['productSupply','productCategory'])->where($where)->order('id desc') ->paginate([ 'list_rows' => 15, 'page' => array_key_exists("page", $search) ? (string)$search['page'] : "1", 'query' => $search ], false)->each(function ($item, $key) { return $item; }); $categoryList = $category_model->getAllData(['uid' => UID], 'id,name', 'sort desc'); $attach = [ 'total_html' => [['总数', $dataList->total()]], ]; View::assign('attach', $attach); View::assign('search', $search); View::assign('dataList', $dataList); View::assign('categoryList', $categoryList); return View::fetch(); } /** * 材料列表导出 */ public function productExport() { $where = session('where'); $hasWhere = session('hasWhere'); $product_model = new FireProduct(); $dataList = $product_model::hasWhere('productSupply',$hasWhere)->with(['productSupply','productCategory'])->where($where)->order('id desc') ->select()->each(function ($item, $key) { $item['status_text'] = $item['status_text']; return $item; }); foreach ($dataList as $key => $value) { $data[$key] = [ $value['id'], //ID $value['name'], //商品名称 $value['category_name'], //分类 $value['company_name'], //供应商 $value['mobile_phone'], //供应商电话 $value['status_text'], //状态 $value['create_time'], //创建时间 ]; }; $fileName = "材料列表"; $headArr = ["ID", "商品名称", '分类', "供应商", "供应商电话", "状态", "状态", "创建时间"]; $msg = ''; $excel_class = new Excel(); $res = $excel_class->excelExport($fileName, $headArr, $data, $msg); return $res; } /** * 材料详情 * @return string */ public function productDetail() { $product_model = new FireProduct(); if (request()->isPost()) { $data = input('post.'); if ($data['name'] == "") { return sendErrorMessage(1,'请填写新闻标题'); } $data['uid'] = UID; Db::startTrans(); $news_id = $product_model->dataUpdate($data); if (!$news_id) { Db::rollback(); return sendErrorMessage(); } Db::commit(); return sendSuccessMessage(); } else { $id = input('param.id', 0); $data = $product_model->with(['productCategory'])->where(['id' => $id])->find(); View::assign('data', $data); return View::fetch('productdetail'); } } /** * 材料审核通过 * @return \think\response\Json */ public function productAdopt() { $id = input('param.id', 0); if (empty($id)) { return sendErrorMessage(1, '参数错误,审核状态变更失败!'); } $product_model = new FireProduct(); Db::startTrans(); $res = $product_model->where(['id'=>$id])->update(['status'=>3]); if ($res === false) { Db::rollback(); return json($res); } Db::commit(); return sendSuccessMessage('', '审核成功'); } /** * 材料审核拒绝 * @return \think\response\Json */ public function productRefuse() { $product_model = new FireProduct(); if (request()->isPost()) { $data = input(); Db::startTrans(); $res = $product_model->where(['id'=>$data['id']])->update(['status'=>5,'examine_idea'=>$data['examine_idea']]); if ($res === false) { Db::rollback(); return sendErrorMessage(1, '审核失败'); } Db::commit(); return sendSuccessMessage('', '审核拒绝成功'); } else { $id = input('param.id'); $data = $product_model->getOneData(['id' => $id]); View::assign('data', $data); return View::fetch('productrefuse'); } } /** * 供应商列表 * @return string */ public function supply() { $search = input('get.'); autoSearch(['time', 'name', 'status', 'phone'], $search); $supply_model = new FireSupply(); $where = [['uid','=',UID]]; if ($search['time']) { $time = explode('-', $search['time']); $where[] = ['create_time','between time', [$time[0], $time[1]]]; } if ($search['name']) { $where[] = ['company_name','like', '%' . $search['name'] . '%']; } if ($search['status'] !== '') { $where []= ['status','=',$search['status']]; } if ($search['phone']) { $where[] = ['mobile_phone','like', '%' . $search['phone'] . '%']; } session('where',$where); $dataList = $supply_model->where($where)->order('id desc') ->paginate([ 'list_rows' => 15, 'page' => array_key_exists("page", $search) ? (string)$search['page'] : "1", 'query' => $search ], false)->each(function ($item, $key) { $item['status_text'] = $item['status_text']; return $item; }); $attach = [ 'total_html' => [['总数', $dataList->total()]], ]; View::assign('attach', $attach); View::assign('search', $search); View::assign('dataList', $dataList); return View::fetch(); } /** * 供应商列表导出 * @return mixed */ public function supplyExport() { $where = session('where'); $supply_model = new FireSupply(); $dataList = $supply_model->where($where)->order('id desc') ->select()->each(function ($item, $key) { $item['status_text'] = $item['status_text']; return $item; }); foreach ($dataList as $key => $value) { $data[$key] = [ $value['id'], //ID $value['company_name'], //公司名称 $value['linkman'], //联系人 $value['mobile_phone'], //联系电话 $value['status_text'], //状态 $value['create_time'], //创建时间 ]; }; $fileName = "供应商列表"; $headArr = ["ID", "公司名称", '联系人', "联系电话", "状态", "创建时间"]; $msg = ''; $excel_class = new Excel(); $res = $excel_class->excelExport($fileName, $headArr, $data, $msg); return $res; } /** * 供应商详情 * @return string */ public function supplyDetail() { $supply_model = new FireSupply(); if (request()->isPost()) { $data = input('post.'); if ($data['name'] == "") { return sendErrorMessage(1,'请填写新闻标题'); } $data['uid'] = UID; Db::startTrans(); $news_id = $supply_model->dataUpdate($data); if (!$news_id) { Db::rollback(); return sendErrorMessage(); } Db::commit(); return sendSuccessMessage(); } else { $id = input('param.id', 0); $data = $supply_model->with(['userHead'])->where(['id' => $id])->find(); View::assign('data', $data); return View::fetch('supplydetail'); } } /** * 供应商修改 * @return string|\think\response\Json */ public function supplyUpdate() { $supply_model = new FireSupply(); if (request()->isPost()) { $data = input('post.'); $data['uid'] = UID; Db::startTrans(); $news_id = $supply_model->dataUpdate($data); if (!$news_id) { Db::rollback(); return sendErrorMessage(); } Db::commit(); return sendSuccessMessage(); } else { $id = input('param.id', 0); $data = $supply_model->with(['userHead'])->where(['id' => $id])->find(); View::assign('data', $data); return View::fetch('supplyupdate'); } } /** * 供应商上下架 * @return \think\response\Json */ public function supplyPublish() { $data = input(); $supply_model = new FireSupply(); $product_model = new FireProduct(); $res = $supply_model->where(['id'=>$data['id']])->update(['is_publish'=>$data['value']]); if ($res === false) { return sendErrorMessage(1); } if($data['value'] == 0) { $res = $product_model->where(['supply_id'=>$data['id']])->update(['status'=>3]); if ($res === false) { return sendErrorMessage(1); } } return sendSuccessMessage(''); } /** * 供应商审核通过 * @return \think\response\Json */ public function supplyAdopt() { $id = input('param.id', 0); if (empty($id)) { return sendErrorMessage(1, '参数错误,审核状态变更失败!'); } $supply_model = new FireSupply(); Db::startTrans(); $res = $supply_model->where(['id'=>$id])->update(['status'=>2]); if ($res === false) { Db::rollback(); return json($res); } Db::commit(); $notice_logic = new Notice();; $supply = $supply_model->getOneData(['id'=>$id]); $notice_logic->examineNotice($supply['user_id'],2,2); return sendSuccessMessage('', '审核成功'); } /** * 供应商审核拒绝 * @return \think\response\Json */ public function supplyRefuse() { $supply_model = new FireSupply(); if (request()->isPost()) { $data = input(); Db::startTrans(); $res = $supply_model->where(['id'=>$data['id']])->update(['status'=>3,'examine_idea'=>$data['examine_idea']]); if ($res === false) { Db::rollback(); return sendErrorMessage(1, '审核失败'); } Db::commit(); $notice_logic = new Notice();; $supply = $supply_model->getOneData(['id'=>$data['id']]); $notice_logic->examineNotice($supply['user_id'],2,3); return sendSuccessMessage('', '审核拒绝成功'); } else { $id = input('param.id'); $data = $supply_model->getOneData(['id' => $id]); View::assign('data', $data); return View::fetch('supplyrefuse'); } } }