Engineer.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\store\controller;
  15. use library\Controller;
  16. use think\Db;
  17. /**
  18. * 工程师管理
  19. * Class GoodsCate
  20. * @package app\store\controller
  21. */
  22. class Engineer extends Controller
  23. {
  24. /**
  25. * 绑定数据表
  26. * @var string
  27. */
  28. protected $table = 'store_engineer';
  29. /**
  30. * 工程师管理
  31. * @auth true
  32. * @menu true
  33. * @throws \think\Exception
  34. * @throws \think\db\exception\DataNotFoundException
  35. * @throws \think\db\exception\ModelNotFoundException
  36. * @throws \think\exception\DbException
  37. * @throws \think\exception\PDOException
  38. */
  39. public function index()
  40. {
  41. $this->title = '工程师列表';
  42. $query = $this->_query($this->table)->where('is_deleted',0)->like('name,phone');
  43. $query->dateBetween('create_at')->order('id desc')->page();
  44. }
  45. /**
  46. * 数据列表处理
  47. * @param array $data
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. * @throws \think\exception\DbException
  51. */
  52. protected function _index_page_filter(&$data)
  53. {
  54. foreach ($data as $k=>&$v){
  55. }
  56. }
  57. /**
  58. * 表单数据处理
  59. * @param array $data
  60. * @throws \think\Exception
  61. * @throws \think\db\exception\DataNotFoundException
  62. * @throws \think\db\exception\ModelNotFoundException
  63. * @throws \think\exception\DbException
  64. * @throws \think\exception\PDOException
  65. */
  66. protected function _form_filter(&$data)
  67. {
  68. if ($this->request->isGet()) {
  69. }elseif ($this->request->isPost()){
  70. if(!preg_match("/^1[23456789]\d{9}$/", $data['phone'])){
  71. $this->error('手机号格式不正确');
  72. }
  73. if(empty($data['headimg'])){
  74. $this->error('请上传头像');
  75. }
  76. //查看手机号是否已有账号
  77. $engineer_id = Db::name('store_engineer')->where('phone',$data['phone'])->value('id');
  78. if($engineer_id){
  79. $this->error('该手机号已有账号');
  80. }
  81. }
  82. }
  83. /**
  84. * 表单结果处理
  85. * @param boolean $result
  86. */
  87. protected function _form_result($result)
  88. {
  89. $phone = Db::name('store_engineer')->where('id',$result)->value('phone');
  90. $system_user_data = array(
  91. 'username' => $phone,
  92. 'authorize'=> 1,
  93. 'password' => md5( substr($phone,-6)),
  94. 'engineer_id' => $result
  95. );
  96. Db::name('system_user')->insert($system_user_data);
  97. }
  98. /**
  99. * 添加工程师
  100. * @auth true
  101. * @throws \think\Exception
  102. * @throws \think\db\exception\DataNotFoundException
  103. * @throws \think\db\exception\ModelNotFoundException
  104. * @throws \think\exception\DbException
  105. * @throws \think\exception\PDOException
  106. */
  107. public function add()
  108. {
  109. $this->title = '添加工程师';
  110. $this->_form($this->table, 'form');
  111. }
  112. /**
  113. * 编辑工程师
  114. * @auth true
  115. * @throws \think\Exception
  116. * @throws \think\db\exception\DataNotFoundException
  117. * @throws \think\db\exception\ModelNotFoundException
  118. * @throws \think\exception\DbException
  119. * @throws \think\exception\PDOException
  120. */
  121. public function edit()
  122. {
  123. $this->title = '编辑工程师';
  124. $this->_form($this->table, 'form');
  125. }
  126. /**
  127. * 删除工程师
  128. * @auth true
  129. * @throws \think\Exception
  130. * @throws \think\exception\PDOException
  131. */
  132. public function remove()
  133. {
  134. $id_arr = explode(',',$_POST['id']);
  135. //删除系统用户
  136. foreach ($id_arr as $value){
  137. Db::name('system_user')->where('engineer_id',$value)->update(array('is_deleted'=>1));
  138. }
  139. $this->_save($this->table, ['is_deleted' => '1']);
  140. }
  141. }