Index.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. //总月份
  62. $total_month = intval(ceil(($val['endtime'] - $val['starttime']) / 2592000));
  63. $total_month = $total_month < 0 ? 0 : $total_month;
  64. //剩余月份
  65. $end_month = intval(ceil(($val['endtime'] - time()) / 2592000));
  66. $end_month = $end_month < 0 ? 0 : $end_month;
  67. //比例
  68. $bili = 100;
  69. if($total_month > 0 && $total_month > $end_month){
  70. $bili = bcdiv(($total_month - $end_month) * 100 , $total_month,0);
  71. }
  72. //追加数据
  73. $list[$key]['total_month'] = $total_month;
  74. $list[$key]['bili'] = $bili;
  75. $list[$key]['end_month'] = $end_month;
  76. }
  77. }
  78. //左侧下面扇形
  79. $wancheng = Db::name('maintain')->where('company_id',$this->auth->company_id)->where('status',100)->count();
  80. $weiwancheng = Db::name('maintain')->where('company_id',$this->auth->company_id)->where('status',2)->count();
  81. $jinxingzhong = Db::name('maintain')->where('company_id',$this->auth->company_id)->where('status','NOTIN',[2,100])->count();
  82. $shanxing = [
  83. ['name'=>'完成数','value'=>$wancheng,'itemStyle'=>['color'=>'#FABA26']],
  84. ['name'=>'未完成数','value'=>$weiwancheng,'itemStyle'=>['color'=>'#15DB92']],
  85. ['name'=>'进行中','value'=>$jinxingzhong,'itemStyle'=>['color'=>'#2AA1FF']],
  86. ];
  87. $shanxing_number = $wancheng + $weiwancheng + $jinxingzhong;
  88. //中间地图
  89. $map_data = [];
  90. if(!empty($list)){
  91. foreach($list as $key => $val){
  92. $map_data[$val['projectname']] = [$val['longitude'],$val['latitude']];
  93. }
  94. }
  95. //中间底部
  96. $maintainlist = Db::name('maintain')->field('id,DATE(FROM_UNIXTIME(createtime)) as createdate')->where('company_id',$this->auth->company_id)->whereTime('createtime','week')->select();
  97. $maindate = array_column($maintainlist,'createdate');
  98. $maindate = array_count_values($maindate);
  99. $maindate = [
  100. 'date' => array_keys($maindate),
  101. 'value'=> array_values($maindate),
  102. ];
  103. // dump($maindate);
  104. //导航
  105. $menus = $this->auth->get_menus_simple();
  106. //结果
  107. $week = [
  108. 1 => '星期一',
  109. 2 => '星期二',
  110. 3 => '星期三',
  111. 4 => '星期四',
  112. 5 => '星期五',
  113. 6 => '星期六',
  114. 0 => '星期天',
  115. ];
  116. $rs = [
  117. 'date' => date('Y.m.d'),
  118. 'week' => $week[date('w')],
  119. 'time' => date('H:i:s'),
  120. 'project' => $list,
  121. 'map_data'=> $map_data,
  122. 'shanxing' => $shanxing,
  123. 'shanxing_number' => $shanxing_number,
  124. 'maindate' => $maindate,
  125. 'menus' => $menus,
  126. ];
  127. $this->success(1,$rs);
  128. }
  129. /**
  130. * 退出登录
  131. * @ApiMethod (POST)
  132. */
  133. public function logout()
  134. {
  135. PcAdminLog::setTitle('退出登录');
  136. if (!$this->request->isPost()) {
  137. $this->error(__('Invalid parameters'));
  138. }
  139. $this->auth->logout();
  140. $this->success('退出成功');
  141. }
  142. //用户详细资料
  143. public function getUserinfo(){
  144. PcAdminLog::setTitle('获取信息');
  145. $info = $this->auth->getUserInfo();
  146. $this->success(__('success'),$info);
  147. }
  148. //用户申请资料
  149. public function getUserapplyinfo(){
  150. $field = [
  151. 'company_name',
  152. 'company_code',
  153. 'company_registerdate',
  154. 'company_address',
  155. 'company_image',
  156. 'truename',
  157. 'idcard',
  158. 'idcard_images',
  159. 'bank_name',
  160. 'bank_branchname',
  161. 'bank_account',
  162. 'bank_card',
  163. ];
  164. $info = Db::name('company')->field($field)->where('id',$this->auth->id)->find();
  165. $info = info_domain_image($info,['company_image','idcard_images']);
  166. $this->success(1,$info);
  167. }
  168. /**
  169. * 修改会员个人信息
  170. *
  171. * @ApiMethod (POST)
  172. * @param string $avatar 头像地址
  173. * @param string $username 用户名
  174. * @param string $nickname 昵称
  175. * @param string $bio 个人简介
  176. */
  177. public function profile()
  178. {
  179. //检查
  180. $check = Db::name('company')->where('id',$this->auth->id)->find();
  181. if($check['status'] == 1){
  182. $this->success('资料审核通过后需联系客服修改');
  183. }
  184. $field = [
  185. 'company_name',
  186. 'company_code',
  187. 'company_registerdate',
  188. 'company_address',
  189. 'company_image',
  190. 'truename',
  191. 'idcard',
  192. 'idcard_images',
  193. 'bank_name',
  194. 'bank_branchname',
  195. 'bank_account',
  196. 'bank_card',
  197. ];
  198. $data = request_post_hub($field);
  199. $data['status'] = 0;
  200. $update_rs = Db::name('company')->where('id',$this->auth->id)->update($data);
  201. $this->success('资料更新完成');
  202. }
  203. }