Demand.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace app\operate\controller;
  3. use app\common\model\User;
  4. use app\common\model\UserMessage;
  5. use library\Controller;
  6. use think\Db;
  7. use library\tools\Data;
  8. /**
  9. * 需求
  10. * Class Demand
  11. * @package app\operate\controller
  12. */
  13. class Demand extends Controller
  14. {
  15. protected $table = 'UserDemand';
  16. /**
  17. * 列表
  18. * @auth true
  19. * @menu true
  20. * @throws \think\Exception
  21. * @throws \think\db\exception\DataNotFoundException
  22. * @throws \think\db\exception\ModelNotFoundException
  23. * @throws \think\exception\DbException
  24. * @throws \think\exception\PDOException
  25. */
  26. public function index()
  27. {
  28. $this->title = '列表';
  29. $where = [];
  30. $where[] = ['f.is_deleted','=',0];
  31. if($title = input('title')) $where[] = ['f.title','like','%'.$title.'%'];
  32. if($name = input('name')) $where[] = ['u.name','like','%'.$name.'%'];
  33. if($phone = input('phone')) $where[] = ['u.phone','=',$phone];
  34. $query = $this->_query($this->table)->alias('f')
  35. ->field('f.*,u.name,u.phone,u.headimg')
  36. ->leftJoin('store_member u','u.id = f.user_id')
  37. ->where($where)
  38. ->order('sort desc,f.id desc')->page();
  39. }
  40. /**
  41. * 删除
  42. * @auth true
  43. * @throws \think\Exception
  44. * @throws \think\exception\PDOException
  45. */
  46. public function del()
  47. {
  48. $this->_save($this->table, ['is_deleted' => '1']);
  49. }
  50. /**
  51. * 编辑
  52. * @auth true
  53. * @menu true
  54. * @throws \think\Exception
  55. * @throws \think\db\exception\DataNotFoundException
  56. * @throws \think\db\exception\ModelNotFoundException
  57. * @throws \think\exception\DbException
  58. * @throws \think\exception\PDOException
  59. */
  60. public function edit()
  61. {
  62. $this->title = '编辑';
  63. $this->_form($this->table, 'form');
  64. }
  65. protected function _form_filter(&$data)
  66. {
  67. if($this->request->isGet()) $this->user_info = Db::name('store_member')->find($data['user_id']);
  68. if($this->request->isPost())
  69. {
  70. $user_demand = Db::name('user_demand')->find($data['id']);
  71. // if($user_demand['status'] != 0) $this->error('不能重复审核');
  72. if($data['status'] > 0 ) UserMessage::sendUserMessage($data['user_id'],'demand',2,$data['status']-1,0,$data['id']);
  73. }
  74. }
  75. protected function _form_result($result){
  76. if($this->request->isPost() && in_array($this->request->action(),['edit']))
  77. {
  78. $user_demand = Db::name('user_demand')->find($result);
  79. if($user_demand['status'] == 1){
  80. $demand_data = [
  81. 'user_id' => $user_demand['user_id'],
  82. 'title' => $user_demand['title'],
  83. 'content' => $user_demand['content'],
  84. 'status' => 1,
  85. 'money' => $user_demand['money'],
  86. 'rel_id' => $user_demand['id'],
  87. 'cover' => $user_demand['cover'],
  88. 'company' => $user_demand['company'],
  89. 'images' => $user_demand['images'],
  90. 'label' => $user_demand['label'],
  91. 'company_logo' => $user_demand['company_logo'],
  92. ];
  93. Data::save("PlatformDemand",$demand_data,'rel_id',['rel_id'=>$result]);
  94. }
  95. $this->success('操作成功', 'javascript:history.back()');
  96. }
  97. }
  98. }