Index.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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',date('Y-m-01'));
  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. 'status' => 3,
  82. ];
  83. if($this->auth->type == 2){
  84. $map['staff_id'] = $this->auth->id;
  85. }
  86. for($i=$starttime;$i<$endtime;$i+=86400){
  87. $starttime_i = $i;
  88. $endtime_i = $i + 86399;
  89. //日历
  90. $ec_date[] = date('d',$starttime_i).'日';
  91. //下单人数
  92. $map['finish_time'] = ['between',[$starttime_i,$endtime_i]];
  93. $ec_ordernum[] = Db::name('order')->where($map)->count('id');
  94. }
  95. //饼图
  96. $map['finish_time'] = ['between',[$starttime,$endtime]];
  97. $servicetype = Db::name('servicetype')->field('id,title as name')->select();
  98. foreach($servicetype as $key => &$val){
  99. $map['servicetype_id'] = $val['id'];
  100. $val['value'] = Db::name('order')->where($map)->count('id');
  101. unset($val['id']);
  102. }
  103. $result = [
  104. 'ec_data' => $ec_date,
  105. 'ec_ordernum' => $ec_ordernum,
  106. 'servicetype' => $servicetype,
  107. ];
  108. $this->success(1,$result);
  109. }
  110. public function datacenter_two(){
  111. $usernumber = Db::name('user_wallet')->where('company_id',$this->auth->company_id)->count();//充卡客户数量
  112. $summoney = Db::name('user_wallet')->where('company_id',$this->auth->company_id)->sum('money');//充卡余额
  113. //客户类别
  114. $comefrom_config = ['自然进店','平台引流','线下新客','老带新'];
  115. $comefrom_array = [];
  116. foreach($comefrom_config as $key => $val){
  117. $number = Db::name('user_wallet')->where('company_id',$this->auth->company_id)->where('comefrom',$val)->count();
  118. $bili = bcdiv($number*100,$usernumber,2).'%';
  119. $comefrom_array[] = ['name'=>$val,'value'=>$bili];
  120. }
  121. //
  122. $result = [
  123. 'usernumber' => $usernumber,
  124. 'summoney' => $summoney,
  125. 'comefrom_array' => $comefrom_array,
  126. ];
  127. $this->success(1,$result);
  128. }
  129. public function datacenter_three(){
  130. $type = input('type',1);
  131. $servicetype = Db::name('servicetype')->field('id,title as name')->select();
  132. //七日
  133. if($type == 1){
  134. $starttime = strtotime(date('Y-m-d')) - 518400;
  135. $endtime = strtotime(date('Y-m-d')) + 86399;
  136. $ec_date = [];
  137. $map = [
  138. 'company_id' => $this->auth->company_id,
  139. 'status' => 3,
  140. ];
  141. if($this->auth->type == 2){
  142. $map['staff_id'] = $this->auth->id;
  143. }
  144. for($i=$starttime;$i<$endtime;$i+=86400){
  145. $starttime_i = $i;
  146. $endtime_i = $i + 86399;
  147. //日历
  148. $ec_date[] = date('d',$starttime_i).'日';
  149. }
  150. foreach($servicetype as $key => &$val){
  151. $map['servicetype_id'] = $val['id'];
  152. $val['data'] = [];
  153. $val['textColor'] = '#FFFFFF';
  154. for($i=$starttime;$i<$endtime;$i+=86400){
  155. $starttime_i = $i;
  156. $endtime_i = $i + 86399;
  157. //销售金额
  158. $map['finish_time'] = ['between',[$starttime_i,$endtime_i]];
  159. $val['data'][] = Db::name('order')->where($map)->sum('total_fee');
  160. }
  161. unset($val['id']);
  162. }
  163. $result = [
  164. 'ec_data' => $ec_date,
  165. 'ec_totalfee' => $servicetype,
  166. ];
  167. $this->success(1,$result);
  168. }else{
  169. $thismonth = strtotime(date('Y-m-01'));
  170. $ec_date = [];
  171. $map = [
  172. 'company_id' => $this->auth->company_id,
  173. 'status' => 3,
  174. ];
  175. if($this->auth->type == 2){
  176. $map['staff_id'] = $this->auth->id;
  177. }
  178. for($i=5;$i>=0;$i--){
  179. $starttime_i = strtotime("-".$i." month",$thismonth);
  180. $endtime_i = strtotime("-".($i+1) ." month",$thismonth) - 1;
  181. //日历
  182. $ec_date[] = date('m',$starttime_i).'月';
  183. //dump(date('Y-m-d H:i:s',$starttime_i));
  184. //dump(date('Y-m-d H:i:s',$endtime_i));
  185. }
  186. foreach($servicetype as $key => &$val){
  187. $map['servicetype_id'] = $val['id'];
  188. $val['data'] = [];
  189. $val['textColor'] = '#FFFFFF';
  190. for($i=5;$i>=0;$i-=1){
  191. $starttime_i = strtotime("-".$i." month",$thismonth);
  192. $endtime_i = strtotime("-".($i+1) ." month",$thismonth) - 1;
  193. //销售金额
  194. $map['finish_time'] = ['between',[$starttime_i,$endtime_i]];
  195. $val['data'][] = Db::name('order')->where($map)->sum('total_fee');
  196. }
  197. unset($val['id']);
  198. }
  199. $result = [
  200. 'ec_data' => $ec_date,
  201. 'ec_totalfee' => $servicetype,
  202. ];
  203. $this->success(1,$result);
  204. }
  205. }
  206. public function datacenter_four(){
  207. $date = input('date',date('Y-m-01'));
  208. $starttime = strtotime($date); //月初第一天
  209. $endtime = strtotime("+1 month",$starttime) - 1; //月末最后一天
  210. $staff = Db::name('company_staff')->field('id,truename')->where('type',2)->where('company_id',$this->auth->company_id)->select();
  211. //柱状图
  212. $ec_date = [];
  213. $ec_ordernum = [];
  214. $map = [
  215. 'company_id' => $this->auth->company_id,
  216. 'status' => 3,
  217. 'finish_time' => ['between',[$starttime,$endtime]],
  218. ];
  219. foreach($staff as $key => $val){
  220. //日历
  221. $ec_date[] = $val['truename'];
  222. //下单人数
  223. $map['staff_id'] = $val['id'];
  224. $ec_ordernum[] = Db::name('order')->where($map)->count('id');
  225. }
  226. $result = [
  227. 'ec_data' => $ec_date,
  228. 'ec_ordernum' => $ec_ordernum,
  229. ];
  230. $this->success(1,$result);
  231. }
  232. }