Index.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. $map_data[] = [
  94. 'name' => $val['projectname'],
  95. 'value'=> [$val['longitude'],$val['latitude'],9],
  96. ];
  97. }
  98. }
  99. //中间底部
  100. $maintainlist = Db::name('maintain')->field('id,DATE(FROM_UNIXTIME(createtime)) as createdate')->where('company_id',$this->auth->company_id)/*->whereTime('createtime','week')*/->select();
  101. $maindate = array_column($maintainlist,'createdate');
  102. $maindate = array_count_values($maindate);
  103. $maindate = [
  104. 'date' => array_keys($maindate),
  105. 'value'=> array_values($maindate),
  106. ];
  107. // dump($maindate);
  108. //导航
  109. $menus = $this->auth->get_menus_simple();
  110. //结果
  111. $week = [
  112. 1 => '星期一',
  113. 2 => '星期二',
  114. 3 => '星期三',
  115. 4 => '星期四',
  116. 5 => '星期五',
  117. 6 => '星期六',
  118. 0 => '星期天',
  119. ];
  120. $rs = [
  121. 'date' => date('Y.m.d'),
  122. 'week' => $week[date('w')],
  123. 'time' => date('H:i:s'),
  124. 'project' => $list,
  125. 'map_data'=> $map_data,
  126. 'shanxing' => $shanxing,
  127. 'shanxing_number' => $shanxing_number,
  128. 'maindate' => $maindate,
  129. 'menus' => $menus,
  130. ];
  131. $this->success(1,$rs);
  132. }
  133. /**
  134. * 退出登录
  135. * @ApiMethod (POST)
  136. */
  137. public function logout()
  138. {
  139. PcAdminLog::setTitle('退出登录');
  140. if (!$this->request->isPost()) {
  141. $this->error(__('Invalid parameters'));
  142. }
  143. $this->auth->logout();
  144. $this->success('退出成功');
  145. }
  146. //用户详细资料
  147. public function getUserinfo(){
  148. PcAdminLog::setTitle('获取信息');
  149. $info = $this->auth->getUserInfo();
  150. $this->success(__('success'),$info);
  151. }
  152. ///////////////////////////下面没用到////////////////////////////////
  153. //用户申请资料
  154. public function getUserapplyinfo(){
  155. $field = [
  156. 'company_name',
  157. 'company_code',
  158. 'company_registerdate',
  159. 'company_address',
  160. 'company_image',
  161. 'truename',
  162. 'idcard',
  163. 'idcard_images',
  164. 'bank_name',
  165. 'bank_branchname',
  166. 'bank_account',
  167. 'bank_card',
  168. ];
  169. $info = Db::name('company')->field($field)->where('id',$this->auth->id)->find();
  170. $info = info_domain_image($info,['company_image','idcard_images']);
  171. $this->success(1,$info);
  172. }
  173. /**
  174. * 修改会员个人信息
  175. *
  176. * @ApiMethod (POST)
  177. * @param string $avatar 头像地址
  178. * @param string $username 用户名
  179. * @param string $nickname 昵称
  180. * @param string $bio 个人简介
  181. */
  182. public function profile()
  183. {
  184. //检查
  185. $check = Db::name('company')->where('id',$this->auth->id)->find();
  186. if($check['status'] == 1){
  187. $this->success('资料审核通过后需联系客服修改');
  188. }
  189. $field = [
  190. 'company_name',
  191. 'company_code',
  192. 'company_registerdate',
  193. 'company_address',
  194. 'company_image',
  195. 'truename',
  196. 'idcard',
  197. 'idcard_images',
  198. 'bank_name',
  199. 'bank_branchname',
  200. 'bank_account',
  201. 'bank_card',
  202. ];
  203. $data = request_post_hub($field);
  204. $data['status'] = 0;
  205. $update_rs = Db::name('company')->where('id',$this->auth->id)->update($data);
  206. $this->success('资料更新完成');
  207. }
  208. }