PlatformDemand.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace app\operate\controller;
  3. use app\common\model\User;
  4. use library\Controller;
  5. use think\Db;
  6. use library\tools\Data;
  7. /**
  8. * 平台需求
  9. * Class PlatformDemand
  10. * @package app\operate\controller
  11. */
  12. class PlatformDemand extends Controller
  13. {
  14. protected $table = 'PlatformDemand';
  15. /**
  16. * 列表
  17. * @auth true
  18. * @menu true
  19. * @throws \think\Exception
  20. * @throws \think\db\exception\DataNotFoundException
  21. * @throws \think\db\exception\ModelNotFoundException
  22. * @throws \think\exception\DbException
  23. * @throws \think\exception\PDOException
  24. */
  25. public function index()
  26. {
  27. $this->title = '列表';
  28. $where = [];
  29. $where[] = ['f.is_deleted','=',0];
  30. if($title = input('title')) $where[] = ['f.title','like','%'.$title.'%'];
  31. $query = $this->_query($this->table)->alias('f')
  32. ->field('f.*,u.name,u.phone,u.headimg')
  33. ->leftJoin('store_member u','u.id = f.user_id')
  34. ->where($where)
  35. ->order('sort desc,f.id asc')->page();
  36. }
  37. /**
  38. * 删除
  39. * @auth true
  40. * @throws \think\Exception
  41. * @throws \think\exception\PDOException
  42. */
  43. public function del()
  44. {
  45. $this->_save($this->table, ['is_deleted' => '1']);
  46. }
  47. /**
  48. * 编辑
  49. * @auth true
  50. * @menu true
  51. * @throws \think\Exception
  52. * @throws \think\db\exception\DataNotFoundException
  53. * @throws \think\db\exception\ModelNotFoundException
  54. * @throws \think\exception\DbException
  55. * @throws \think\exception\PDOException
  56. */
  57. public function add()
  58. {
  59. $this->title = '添加';
  60. $this->_form($this->table, 'form');
  61. }
  62. /**
  63. * 编辑
  64. * @auth true
  65. * @menu true
  66. * @throws \think\Exception
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\ModelNotFoundException
  69. * @throws \think\exception\DbException
  70. * @throws \think\exception\PDOException
  71. */
  72. public function edit()
  73. {
  74. $this->title = '编辑';
  75. $this->_form($this->table, 'form');
  76. }
  77. /**
  78. * 商品上架
  79. * @auth true
  80. * @menu true
  81. * @throws \think\Exception
  82. * @throws \think\db\exception\DataNotFoundException
  83. * @throws \think\db\exception\ModelNotFoundException
  84. * @throws \think\exception\DbException
  85. * @throws \think\exception\PDOException
  86. */
  87. public function up()
  88. {
  89. $this->_save($this->table, ['status' => '1']);
  90. }
  91. /**
  92. * 商品下架
  93. * @auth true
  94. * @menu true
  95. * @throws \think\Exception
  96. * @throws \think\db\exception\DataNotFoundException
  97. * @throws \think\db\exception\ModelNotFoundException
  98. * @throws \think\exception\DbException
  99. * @throws \think\exception\PDOException
  100. */
  101. public function down()
  102. {
  103. $this->_save($this->table, ['status' => '0']);
  104. }
  105. protected function _form_filter(&$data)
  106. {
  107. if($this->request->isGet() && $this->request->action() == 'edit') $this->user_info = Db::name('store_member')->find($data['user_id']);
  108. if($this->request->isPost())
  109. {
  110. if(!empty($data['phone'])) {
  111. $user_id = User::where('phone|email',$data['phone'])->value('id');
  112. if(!$user_id) $this->error('该账号未注册');
  113. $data['user_id'] = $user_id;
  114. }else{
  115. $data['user_id'] = 0;
  116. }
  117. }
  118. }
  119. protected function _form_result($result){
  120. $this->success('操作成功', 'javascript:history.back()');
  121. }
  122. }