Index.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. namespace app\api\controller\company;
  3. use app\common\controller\Apic;
  4. use think\Db;
  5. /**
  6. * 会员接口
  7. */
  8. class Index extends Apic
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = '*';
  12. //首页
  13. public function index(){
  14. }
  15. //首页轮播
  16. public function banner(){
  17. $where = [
  18. 'status' => 1,
  19. 'position' => 1
  20. ];
  21. $list = Db::name('platform_banner')->where($where)->order('weigh asc,id asc')->select();
  22. $list = list_domain_image($list,['image']);
  23. $this->success(1,$list);
  24. }
  25. //商家钱包明细
  26. public function money_log(){
  27. $map = [
  28. 'user_id' => $this->auth->company_id,
  29. ];
  30. $list = Db::name('company_money_log')
  31. ->field('id,log_type,change_value,remain,remark,createtime')
  32. ->where($map)->order('id desc')->autopage()->select();
  33. //$list = $this->list_appen_logtext($list);
  34. $this->success(1,$list);
  35. }
  36. //追加log_text
  37. private function list_appen_logtext($list){
  38. if(!empty($list)){
  39. $conf = config('wallet.logtype');
  40. foreach($list as $key => $val){
  41. $list[$key]['log_text'] = isset($conf[$val['log_type']]) ? $conf[$val['log_type']] : '';
  42. }
  43. }
  44. return $list;
  45. }
  46. //资金账单,用来显示本门店下所有用户的储值卡的流水日志
  47. public function usermoney_info(){
  48. $usernumber = Db::name('user_wallet')->where('company_id',$this->auth->company_id)->count();
  49. $summoney = Db::name('user_wallet')->where('company_id',$this->auth->company_id)->sum('money');
  50. $rs = [
  51. 'usernumber' => $usernumber,
  52. 'summoney' => $summoney,
  53. ];
  54. $this->success(1,$rs);
  55. }
  56. //资金账单,下部列表
  57. public function usermoney_lists(){
  58. $keyword = input('keyword','');
  59. $where = [
  60. 'log.company_id' => $this->auth->company_id,
  61. ];
  62. if(!empty($keyword)){
  63. $where['user.nickname|user.mobile'] = ['LIKE','%'.$keyword.'%'];
  64. }
  65. $lists = Db::name('user_money_log')->alias('log')
  66. ->field('log.id,log.log_type,log.change_value,log.remain,log.remark,log.createtime,user.nickname,user.mobile')
  67. ->join('user','log.user_id = user.id','LEFT')
  68. ->where($where)->autopage()->select();
  69. $this->success(1,$lists);
  70. }
  71. //数据中心
  72. public function datacenter_one(){
  73. $date = input('date',0);
  74. $starttime = strtotime($date); //月初第一天
  75. $endtime = strtotime("+1 month",$starttime) - 1; //月末最后一天
  76. //柱状图
  77. $ec_date = [];
  78. $ec_ordernum = [];
  79. $map = [
  80. 'company_id' => $this->auth->company_id,
  81. ];
  82. if($this->auth->type == 2){
  83. $map['staff_id'] = $this->auth->id;
  84. }
  85. for($i=$starttime;$i<$endtime;$i+=86400){
  86. $starttime_i = $i;
  87. $endtime_i = $i + 86399;
  88. //日历
  89. $ec_date[] = date('d',$starttime_i).'日';
  90. //下单人数
  91. $map['finish_time'] = ['between',[$starttime_i,$endtime_i]];
  92. $ec_ordernum[] = Db::name('order')->where($map)->count('id');
  93. }
  94. //饼图
  95. $map['finish_time'] = ['between',[$starttime,$endtime]];
  96. $servicetype = Db::name('servicetype')->field('id,title as name')->select();
  97. foreach($servicetype as $key => &$val){
  98. $map['servicetype_id'] = $val['id'];
  99. $val['value'] = Db::name('order')->where($map)->count('id');
  100. unset($val['id']);
  101. }
  102. $result = [
  103. 'ec_data' => $ec_date,
  104. 'ec_ordernum' => $ec_ordernum,
  105. 'servicetype' => $servicetype,
  106. ];
  107. $this->success(1,$result);
  108. }
  109. public function datacenter_two(){
  110. $usernumber = Db::name('user_wallet')->where('company_id',$this->auth->company_id)->count();//充卡客户数量
  111. $summoney = Db::name('user_wallet')->where('company_id',$this->auth->company_id)->sum('money');//充卡余额
  112. //客户类别
  113. $comefrom_config = ['自然进店','平台引流','线下新客','老带新'];
  114. $comefrom_array = [];
  115. foreach($comefrom_config as $key => $val){
  116. $number = Db::name('user_wallet')->where('company_id',$this->auth->company_id)->where('comefrom',$val)->count();
  117. $bili = bcdiv($number*100,$usernumber,2).'%';
  118. $comefrom_array[] = ['name'=>$val,'value'=>$bili];
  119. }
  120. //
  121. $result = [
  122. 'usernumber' => $usernumber,
  123. 'summoney' => $summoney,
  124. 'comefrom_array' => $comefrom_array,
  125. ];
  126. $this->success(1,$result);
  127. }
  128. public function datacenter_three(){
  129. $type = input('type',1);
  130. $servicetype = Db::name('servicetype')->field('id,title as name')->select();
  131. //七日
  132. if($type == 1){
  133. $starttime = strtotime(date('Y-m-d')) - 518400;
  134. $endtime = strtotime(date('Y-m-d')) + 86399;
  135. $ec_date = [];
  136. $ec_totalfee = [];
  137. $map = [
  138. 'company_id' => $this->auth->company_id,
  139. ];
  140. if($this->auth->type == 2){
  141. $map['staff_id'] = $this->auth->id;
  142. }
  143. for($i=$starttime;$i<$endtime;$i+=86400){
  144. $starttime_i = $i;
  145. $endtime_i = $i + 86399;
  146. //日历
  147. $ec_date[] = date('d',$starttime_i).'日';
  148. }
  149. foreach($servicetype as $key => &$val){
  150. $map['servicetype_id'] = $val['id'];
  151. $val['data'] = [];
  152. $val['textColor'] = '#FFFFFF';
  153. for($i=$starttime;$i<$endtime;$i+=86400){
  154. $starttime_i = $i;
  155. $endtime_i = $i + 86399;
  156. //销售金额
  157. $map['finish_time'] = ['between',[$starttime_i,$endtime_i]];
  158. $val['data'][] = Db::name('order')->where($map)->sum('total_fee');
  159. }
  160. unset($val['id']);
  161. }
  162. $ec_totalfee = $servicetype;
  163. $result = [
  164. 'ec_data' => $ec_date,
  165. 'ec_totalfee' => $ec_totalfee,
  166. ];
  167. $this->success(1,$result);
  168. }
  169. }
  170. public function datacenter_four(){
  171. }
  172. }