WeixinPush.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. namespace app\command;
  3. // +----------------------------------------------------------------------
  4. // | [ WE CAN DO IT MORE SIMPLE ]
  5. // +----------------------------------------------------------------------
  6. // | Copyright (c) 2018-2020 rights reserved.
  7. // +----------------------------------------------------------------------
  8. // | Author: TABLE ME
  9. // +----------------------------------------------------------------------
  10. // | Date: 2020-09-08 16:19
  11. // +----------------------------------------------------------------------
  12. use app\model\api\SiteDetail;
  13. use app\model\system\Member;
  14. use app\model\system\OrderInfo;
  15. use app\model\system\Product;
  16. use app\model\system\Recharge;
  17. use app\model\system\Site;
  18. use library\lib\weixinjs;
  19. use library\utils\Qiniu;
  20. use think\console\Command;
  21. use think\console\Input;
  22. use think\console\Output;
  23. use think\facade\Db;
  24. /**
  25. * 生成业绩报表
  26. * @author huangjianfeng
  27. */
  28. class WeixinPush extends Command
  29. {
  30. protected function configure()
  31. {
  32. $this
  33. ->setName('WeixinPush')
  34. ->setDescription('每日微信业绩报表')
  35. ->addArgument('action', null, "");
  36. }
  37. protected function execute(Input $input, Output $output)
  38. {
  39. $time = strtotime(date('Y-m-d', strtotime('-1 day')));
  40. $this->expSystemData($time);
  41. $this->expAdminData($time);
  42. }
  43. /**
  44. * [总后台]推送数据
  45. * @param $time
  46. */
  47. private function expSystemData($time) {
  48. $data = Db::name("weixin_push_user")->where('type','system')->select();
  49. $date = date('Y-m-d',$time);
  50. //今日订单量
  51. $post['today_order_count'] = (new \app\model\system\Order())
  52. ->where('status','>',0)
  53. ->whereDay('pay_time',$date)
  54. ->count();
  55. //其他数据
  56. $post['today_t_order_count'] = (new OrderInfo)
  57. ->where('status','>',0)
  58. ->whereDay('time',$date)
  59. ->count();
  60. //今日销售额
  61. $post['today_money'] = (new \app\model\system\Order())
  62. ->where('status','>',0)
  63. ->whereDay('pay_time',$date)
  64. ->sum('all_price');
  65. $post['today_user'] = (new Member)->whereDay('regtime',$date)->count();
  66. $post['today_recharge'] = (new Recharge)->whereDay('time',$date)->where('status',1)->sum('v');
  67. $str = "昨日订单量:".$post['today_order_count'] .'单(其中子订单' . $post['today_t_order_count'] . '单),';
  68. $str .= "昨日销售额:".(empty($post['today_money']) ? '0.00' : $post['today_money']).'元,新增加会员:'. $post['today_user'] .'人,';
  69. $str .= '充值金额:'.(empty($post['today_recharge']) ? '0.00' : $post['today_recharge']) .'元';
  70. $templateAr = [
  71. 'first' => [
  72. 'value' => '昨日业绩汇总',
  73. "color" => "#000000"
  74. ],
  75. 'keyword1' => [
  76. 'value' => $date,
  77. "color" => "#409EFF"
  78. ],
  79. 'keyword2' => [
  80. 'value' => $str,
  81. "color" => "#409EFF"
  82. ],
  83. 'keyword3' => [
  84. 'value' => date('Y-m-d H:i:s'),
  85. "color" => "#409EFF"
  86. ],
  87. 'remark' => [
  88. 'value' => "今天会比昨日更加努力,加油!!!😁😁😁➡️👏👏👏👏\n\t 点击下方菜单,查看详情数据↓↓↓",
  89. "color" => "#f80505"
  90. ],
  91. ];
  92. $weixin = new weixinjs();
  93. foreach ($data as $v) {
  94. $token = base64_encode(crypto_encrypt(serialize(['time'=>$time]),'weixin_push'));
  95. $url = config('app')['API_URL'].'/api/wexinPush/systemTotal?token=' .$token;
  96. $a = $weixin->template('RKHWnRvPWKPBNk0fYuucOGAUu730HW2s0YFXsW_Z4gY',$v['openid'],$templateAr,$url);
  97. //var_dump($a);
  98. }
  99. echo $str.PHP_EOL;
  100. }
  101. /**
  102. * [分站]推送数据
  103. * @param $time
  104. */
  105. private function expAdminData($time) {
  106. $weixin = new weixinjs();
  107. $data = Db::name("weixin_push_user")->where('type','admin')->where('uid',0)->select();
  108. $date = date('Y-m-d',$time);
  109. foreach ($data as $v) {
  110. $siteData = (new Site)->where('sassid',$v['sassid'])->find();
  111. //今日订单量
  112. $post['today_order_count'] = (new \app\model\system\Order())
  113. ->where('status', '>', 0)
  114. ->where('sassid',$v['sassid'])
  115. ->whereDay('pay_time', $date)
  116. ->count();
  117. //其他数据
  118. $post['today_t_order_count'] = (new OrderInfo)
  119. ->where('status', '>', 0)
  120. ->whereDay('time', $date)
  121. ->where('sassid',$v['sassid'])
  122. ->count();
  123. //今日销售额
  124. $post['today_money'] = (new \app\model\system\Order())
  125. ->where('status', '>', 0)
  126. ->whereDay('pay_time', $date)
  127. ->where('sassid',$v['sassid'])
  128. ->sum('all_price');
  129. //
  130. $post['today_user'] = (new Member)->whereDay('regtime', $date)->where('sassid',$v['sassid'])->count();
  131. $post['today_recharge'] = (new Recharge)->whereDay('time', $date)->where('status', 1)->where('sassid',$v['sassid'])->sum('v');
  132. $post['today_commission'] = (new SiteDetail)->where('sassid',$v['sassid'])->where('type',1)->whereDay('time',$date)->sum('v');
  133. $str = "昨日订单量:" . $post['today_order_count'] . '单(其中子订单' . $post['today_t_order_count'] . '单),';
  134. $str .= "昨日销售额:" . (empty($post['today_money']) ? '0.00' : $post['today_money']) . '元,新增加会员:' . $post['today_user'] . '人,';
  135. $str .= '充值金额:' . (empty($post['today_recharge']) ? '0.00' : $post['today_recharge']) . '元';
  136. $str .= ',获取佣金:' . (empty($post['today_commission']) ? '0.00' : $post['today_commission']) . '元';
  137. $templateAr = [
  138. 'first' => [
  139. 'value' => $siteData['name'].'-昨日业绩汇总',
  140. "color" => "#000000"
  141. ],
  142. 'keyword1' => [
  143. 'value' => $date,
  144. "color" => "#409EFF"
  145. ],
  146. 'keyword2' => [
  147. 'value' => $str,
  148. "color" => "#409EFF"
  149. ],
  150. 'keyword3' => [
  151. 'value' => date('Y-m-d H:i:s'),
  152. "color" => "#409EFF"
  153. ],
  154. 'remark' => [
  155. 'value' => "今天会比昨日更加努力,加油!!!😁😁😁➡️👏👏👏👏\n\t 点击下方菜单,查看详情数据↓↓↓",
  156. "color" => "#f80505"
  157. ],
  158. ];
  159. $token = base64_encode(crypto_encrypt(serialize(['time' => $time,'sassid'=>$v['sassid']]), 'weixin_push'));
  160. $url = config('app')['API_URL'] . '/api/wexinPush/adminTotal?token=' . $token;
  161. $a = $weixin->template('RKHWnRvPWKPBNk0fYuucOGAUu730HW2s0YFXsW_Z4gY', $v['openid'], $templateAr, $url);
  162. echo $siteData['name'] . '['.$v['nickname'].']' .$str . PHP_EOL;
  163. }
  164. }
  165. }