Index.php 9.1 KB

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