Index.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. namespace app\company\controller;
  3. use app\common\controller\Apic;
  4. use app\common\model\PcAdminLog;
  5. use fast\Random;
  6. use think\Config;
  7. use think\Validate;
  8. use think\Db;
  9. /**
  10. * 会员接口
  11. */
  12. class Index extends Apic
  13. {
  14. protected $noNeedLogin = ['login'];
  15. protected $noNeedRight = '*';
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. }
  20. /**
  21. * 后台首页
  22. */
  23. public function index()
  24. {
  25. $menus = $this->auth->get_menus();
  26. $permissions = $this->auth->get_permissions();
  27. $rs = [
  28. 'user' => $this->auth->getUserInfo(),
  29. 'permissions' => $permissions,
  30. 'menus' => $menus,
  31. ];
  32. // dump($rs);exit;
  33. $this->success(1,$rs);
  34. }
  35. //员工账号+密码登录
  36. public function login()
  37. {
  38. $username = input('username');
  39. $password = input('password');
  40. if (!$username || !$password) {
  41. $this->error(__('Invalid parameters'));
  42. }
  43. PcAdminLog::setTitle(__('Login'));
  44. //找员工
  45. $ret = $this->auth->login($username, $password);
  46. if ($ret) {
  47. $data = $this->auth->getUserInfo_simple();
  48. $this->success('登录成功', $data);
  49. } else {
  50. $msg = $this->auth->getError();
  51. $msg = $msg ? $msg : __('Username or password is incorrect');
  52. $this->error($msg);
  53. }
  54. }
  55. //大屏幕
  56. public function dashboard(){
  57. //左侧上面条状
  58. $list = Db::name('user_company')->field('id,projectname,starttime,endtime,longitude,latitude')->where('company_id',$this->auth->company_id)->order('endtime asc')->select();
  59. if(!empty($list)){
  60. foreach($list as $key => $val){
  61. $total_month = intval(ceil(($val['endtime'] - $val['starttime']) / 2592000)); //总月份
  62. $total_month = $total_month < 0 ? 0 : $total_month;
  63. $end_month = intval(ceil(($val['endtime'] - time()) / 2592000)); //剩余月份
  64. $end_month = $end_month < 0 ? 0 : $end_month;
  65. $bili = 100;
  66. if($total_month > 0 && $total_month > $end_month){
  67. $bili = bcdiv(($total_month - $end_month) * 100 , $total_month,0);
  68. }
  69. $list[$key]['total_month'] = $total_month;
  70. $list[$key]['bili'] = $bili;
  71. $list[$key]['end_month'] = $end_month;
  72. }
  73. }
  74. //左侧下面扇形
  75. $wancheng = Db::name('maintain')->where('company_id',$this->auth->company_id)->where('status',100)->count();
  76. $weiwancheng = Db::name('maintain')->where('company_id',$this->auth->company_id)->where('status',2)->count();
  77. $jinxingzhong = Db::name('maintain')->where('company_id',$this->auth->company_id)->where('status','NOTIN',[2,100])->count();
  78. $shanxing = [
  79. ['name'=>'完成数','value'=>$wancheng,'itemStyle'=>['color'=>'#FABA26']],
  80. ['name'=>'未完成数','value'=>$weiwancheng,'itemStyle'=>['color'=>'#15DB92']],
  81. ['name'=>'进行中','value'=>$jinxingzhong,'itemStyle'=>['color'=>'#2AA1FF']],
  82. ];
  83. $shanxing_number = $wancheng + $weiwancheng + $jinxingzhong;
  84. //中间地图
  85. //中间底部
  86. $maintainlist = Db::name('maintain')->field('id,DATE(FROM_UNIXTIME(createtime)) as createdate')->where('company_id',$this->auth->company_id)->whereTime('createtime','week')->select();
  87. $maindate = array_column($maintainlist,'createdate');
  88. $maindate = array_count_values($maindate);
  89. $maindate = [
  90. 'date' => array_keys($maindate),
  91. 'value'=> array_values($maindate),
  92. ];
  93. // dump($maindate);
  94. //导航
  95. $menus = $this->auth->get_menus_simple();
  96. //结果
  97. $week = [
  98. 1 => '星期一',
  99. 2 => '星期二',
  100. 3 => '星期三',
  101. 4 => '星期四',
  102. 5 => '星期五',
  103. 6 => '星期六',
  104. 0 => '星期天',
  105. ];
  106. $rs = [
  107. 'date' => date('Y.m.d'),
  108. 'week' => $week[date('w')],
  109. 'time' => date('H:i:s'),
  110. 'project' => $list,
  111. 'shanxing' => $shanxing,
  112. 'shanxing_number' => $shanxing_number,
  113. 'maindate' => $maindate,
  114. 'menus' => $menus,
  115. ];
  116. $this->success(1,$rs);
  117. }
  118. /**
  119. * 退出登录
  120. * @ApiMethod (POST)
  121. */
  122. public function logout()
  123. {
  124. PcAdminLog::setTitle('退出登录');
  125. if (!$this->request->isPost()) {
  126. $this->error(__('Invalid parameters'));
  127. }
  128. $this->auth->logout();
  129. $this->success('退出成功');
  130. }
  131. //用户详细资料
  132. public function getUserinfo(){
  133. PcAdminLog::setTitle('获取信息');
  134. $info = $this->auth->getUserInfo();
  135. $this->success(__('success'),$info);
  136. }
  137. //用户申请资料
  138. public function getUserapplyinfo(){
  139. $field = [
  140. 'company_name',
  141. 'company_code',
  142. 'company_registerdate',
  143. 'company_address',
  144. 'company_image',
  145. 'truename',
  146. 'idcard',
  147. 'idcard_images',
  148. 'bank_name',
  149. 'bank_branchname',
  150. 'bank_account',
  151. 'bank_card',
  152. ];
  153. $info = Db::name('company')->field($field)->where('id',$this->auth->id)->find();
  154. $info = info_domain_image($info,['company_image','idcard_images']);
  155. $this->success(1,$info);
  156. }
  157. /**
  158. * 修改会员个人信息
  159. *
  160. * @ApiMethod (POST)
  161. * @param string $avatar 头像地址
  162. * @param string $username 用户名
  163. * @param string $nickname 昵称
  164. * @param string $bio 个人简介
  165. */
  166. public function profile()
  167. {
  168. //检查
  169. $check = Db::name('company')->where('id',$this->auth->id)->find();
  170. if($check['status'] == 1){
  171. $this->success('资料审核通过后需联系客服修改');
  172. }
  173. $field = [
  174. 'company_name',
  175. 'company_code',
  176. 'company_registerdate',
  177. 'company_address',
  178. 'company_image',
  179. 'truename',
  180. 'idcard',
  181. 'idcard_images',
  182. 'bank_name',
  183. 'bank_branchname',
  184. 'bank_account',
  185. 'bank_card',
  186. ];
  187. $data = request_post_hub($field);
  188. $data['status'] = 0;
  189. $update_rs = Db::name('company')->where('id',$this->auth->id)->update($data);
  190. $this->success('资料更新完成');
  191. }
  192. }