Bidding.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. namespace app\admin\controller;
  3. use app\data\model\BasePostageRegion;
  4. use app\data\model\DataBidding;
  5. use app\data\model\DataBidding as Model;
  6. use app\data\model\DataBiddingType;
  7. use think\admin\Controller;
  8. /**
  9. * 招标中心
  10. * Class Xw
  11. * @package app\admin\controller\Xw
  12. */
  13. class Bidding extends Controller
  14. {
  15. /**
  16. * 招标列表
  17. * @auth true
  18. * @menu true
  19. */
  20. public function index(){
  21. $this->title='招标列表';
  22. $this->assign('type',DataBiddingType::select());
  23. Model::mQuery()
  24. ->with(['type'])
  25. ->equal('type_id')
  26. ->like('title')->dateBetween('create_time')->layTable();
  27. }
  28. /**
  29. * 招标添加
  30. * @auth true
  31. * @menu true
  32. */
  33. public function add(){
  34. $this->title='招标添加';
  35. $this->xw_vali();
  36. $this->assign('category',DataBiddingType::select());
  37. $this->assign('city',BasePostageRegion::getCity());
  38. Model::mForm('form');
  39. }
  40. /**
  41. * 招标编辑
  42. * @auth true
  43. * @menu true
  44. */
  45. public function edit(){
  46. $this->title='招标编辑';
  47. $this->xw_vali();
  48. $this->assign('category',DataBiddingType::select());
  49. $this->assign('city',BasePostageRegion::getCity());
  50. Model::mForm('form');
  51. }
  52. protected function xw_vali(){
  53. if($this->request->isPost()){
  54. $this->_vali([
  55. 'title.max:50'=>'标题过长',
  56. ]);
  57. }
  58. }
  59. /**
  60. * 招标删除
  61. * @auth true
  62. * @menu true
  63. */
  64. public function remove(){
  65. $ids=$this->request->post('id');
  66. Model::whereIn('id',$ids)->select()->each(function ($d){$d->delete();});
  67. $this->success('删除成功');
  68. }
  69. /**
  70. * 招标设置
  71. * @auth true
  72. * @menu true
  73. */
  74. public function config(){
  75. if($this->request->isGet()){
  76. $this->title='招标设置';
  77. $this->assign('vo',sysconf('config_res_center.'));
  78. $this->fetch();
  79. }else{
  80. $data=$this->_vali([
  81. 'c_rule.require'=>'规则数必须',
  82. 'c_conv.require'=>'公约数必须',
  83. 'c_menu.require'=>'清单数必须',
  84. ]);
  85. sysconf('config_res_center',$data);
  86. $this->success('保存成功');
  87. }
  88. }
  89. /**
  90. * 招标类型管理
  91. * @auth true
  92. * @menu true
  93. */
  94. public function type(){
  95. $this->title='招标类型管理';
  96. DataBiddingType::mQuery()
  97. ->layTable();
  98. }
  99. /**
  100. * 招标类型管理
  101. * @auth true
  102. * @menu true
  103. */
  104. public function type_add(){
  105. if($this->request->isPost()){
  106. $data=$this->_vali([
  107. 'name.require'=>'名称必须',
  108. ]);
  109. DataBiddingType::create($data);
  110. $this->success('保存成功');
  111. }
  112. $this->fetch('type_form');
  113. }
  114. /**
  115. * 招标类型管理
  116. * @auth true
  117. * @menu true
  118. */
  119. public function type_edit(){
  120. if($this->request->isPost()){
  121. $data=$this->_vali([
  122. 'name.require'=>'名称必须',
  123. ]);
  124. DataBiddingType::where('id',input('id'))->save($data);
  125. $this->success('保存成功');
  126. }else{
  127. $this->assign('vo',DataBiddingType::find(input('id')));
  128. $this->fetch('type_form');
  129. }
  130. }
  131. /**
  132. * 招标类型管理
  133. * @auth true
  134. * @menu true
  135. */
  136. public function type_remove(){
  137. $ids=$this->request->post('id');
  138. $has=DataBidding::whereIn('type_id',$ids)->find();
  139. if($has){
  140. $this->error('该分类下还有招标,请删除后再试');
  141. }
  142. DataBiddingType::whereIn('id',$ids)->select()->each(function ($d){
  143. $d->delete();
  144. });
  145. $this->success('删除成功');
  146. }
  147. /**
  148. * 表单结果处理
  149. * @param boolean $state
  150. */
  151. protected function _form_result(bool $state)
  152. {
  153. if ($state) {
  154. $this->success('保存成功!', 'javascript:history.back()');
  155. }
  156. }
  157. /**
  158. * 中标
  159. * @auth true
  160. */
  161. public function make_bidding(){
  162. $id = input('id');
  163. $bidding=DataBidding::find($id);
  164. $this->assign('vo',$bidding);
  165. if($bidding->win){
  166. //$this->error('该招标已中标');
  167. }
  168. if($this->request->isGet()) {
  169. $this->fetch();
  170. }else{
  171. $data=$this->_vali([
  172. 'com_name.require'=>'公司名称必须',
  173. 'com_username.require'=>'公司联系人必须',
  174. 'com_mobile.require'=>'公司手机号必须',
  175. ]);
  176. $bidding->win()->save($data);
  177. $bidding->status=1;
  178. $bidding->save();
  179. $this->success('中标成功');
  180. }
  181. }
  182. }