TeamValue.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020/6/23
  7. *
  8. *
  9. */
  10. namespace app\controller\admin\user;
  11. use app\common\dao\BaseDao;
  12. use app\common\model\system\admin\Log;
  13. use crmeb\basic\BaseController;
  14. use app\common\repositories\user\UserBillRepository;
  15. use think\console\command\make\Controller;
  16. use think\Request;
  17. class TeamValue extends Controller
  18. {
  19. protected $repository;
  20. protected $request;
  21. public function __construct(Request $request)
  22. {
  23. parent::__construct();
  24. $this->request = $request;
  25. }
  26. /**
  27. * 团队设置信息
  28. * @return mixed
  29. * @throws \think\db\exception\DataNotFoundException
  30. * @throws \think\db\exception\DbException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. *
  33. *
  34. */
  35. public function getInfo()
  36. {
  37. $where = ['create_time'];
  38. $info=\app\common\model\user\TeamValue::where('create_time >0')->find();
  39. // \think\facade\Log::info('ddddd');
  40. $msg='成功';
  41. return app('json')->success('',$info);
  42. // echo 'eeeee';
  43. }
  44. /**
  45. * 编辑团队设置信息
  46. * @return mixed
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\DbException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. */
  51. public function editInfo(){
  52. $params=$this->request->params(['id','sum']);;
  53. $info=\app\common\model\user\TeamValue::where('create_time >0')->find();
  54. $res=$info->save(['sum'=>$params['sum']]);
  55. if($res){
  56. $msg='成功';
  57. }else{
  58. $msg="失败";
  59. }
  60. return app('json')->success($msg,$res);
  61. }
  62. public function type()
  63. {
  64. return app('json')->success($this->repository->type());
  65. }
  66. /*平台记录*/
  67. public function adminList(){
  68. [$page, $limit] = $this->getPage();
  69. $where = $this->request->params(['keyword', 'date', 'type']);
  70. return app('json')->success($this->repository->getAdminList($where, $page, $limit));
  71. // return app('json')->success($this->repository->getAdminList($where, $page, $limit));
  72. }
  73. public function excel()
  74. {
  75. $where = request()->params(['date']);
  76. $params = request()->params(['commission_type', 'uid', 'status', 'phone', 'user_group', 'status']);
  77. $commission_type_desc = '佣金统计';
  78. if ($params['commission_type'] ?? 0 == 5) {
  79. $commission_type_desc = '养老金统计';
  80. }
  81. $data = [];
  82. //商户ID
  83. $mer_id = 0;
  84. $query = Db::name('user_bill')
  85. ->alias('ub')
  86. ->leftJoin('user u', 'u.uid=ub.uid')
  87. ->when($mer_id, function ($query) use ($mer_id) {
  88. $query->where('ub.mer_id', $mer_id);
  89. })
  90. ->when(isset($params['commission_type']) && $params['commission_type'] == 5, function ($query) use ($params) {
  91. // 养老金
  92. $query->where('ub.commission_type', 5);
  93. }, function ($query) use ($params) {
  94. // 非养老金
  95. $query->whereIn('ub.commission_type', [3, 16, 14, 10, 12, 20, 15, 7, 19]);
  96. })
  97. ->when(isset($params['uid']) && $params['uid'] != '', function ($query) use ($params) {
  98. $query->where('ub.uid', $params['uid']);
  99. })
  100. ->when(isset($params['commission_type']) && $params['commission_type'] != '', function ($query) use ($params) {
  101. $query->where('ub.commission_type', $params['commission_type']);
  102. })
  103. ->when(isset($params['status']) && $params['status'] != '', function ($query) use ($params) {
  104. $query->where('ub.status', $params['status']);
  105. })
  106. ->when(isset($params['phone']) && $params['phone'] != '', function ($query) use ($params) {
  107. $query->whereLike('u.phone', '%' . $params['phone'] . '%');
  108. })
  109. ->when(isset($params['user_group']) && $params['user_group'] != '', function ($query) use ($params) {
  110. $query->where('u.user_group', $params['user_group']);
  111. });
  112. $financeRepository = app()->make(FinanceRepository::class);
  113. $list = $financeRepository->date_where($query, $where['date'], 'ub.create_time')
  114. ->field('ub.bill_id,ub.title,ub.number,ub.take_time,ub.commission_type,u.uid,u.phone,u.nickname,u.user_group,ub.order_sn,ub.take_time,ub.status,ub.create_time')
  115. ->order('ub.bill_id', 'desc')
  116. ->select()
  117. ->each(function ($item) {
  118. if($item['take_time'])
  119. $item['take_time'] = date('Y-m-d H:i:s', $item['take_time']);
  120. return $item;
  121. });
  122. foreach ($list as $k => $v) {
  123. $temp = array(
  124. $v['bill_id'],
  125. $v['create_time'],
  126. $v['nickname'],
  127. $v['phone'],
  128. $v['title'],
  129. $v['number'],
  130. $v['status'] == 1 ? '已结算': '未结算',
  131. $v['order_sn'] ?? '',
  132. );
  133. $arr[] = $temp;
  134. }
  135. $header = [
  136. 'ID', '创建时间', '用户昵称', '用户手机号', '名称', '金额', '状态', '订单号'
  137. ];
  138. $filename = $commission_type_desc . date('YmdHis') . '_' . rand(10000, 99999);
  139. $title = $commission_type_desc;
  140. $name = $commission_type_desc;
  141. $info = '生成时间:' . date('Y-m-d H:i:s', time());
  142. $suffix = 'xlsx';
  143. $path = 'extract';
  144. unset($_instance);
  145. $_instance = SpreadsheetExcelService::instance_xin();
  146. $_path = $_instance
  147. ->createOrActive()
  148. ->setExcelHeader($header)
  149. ->setExcelTile($title, $name, $info)
  150. ->setExcelContent($arr)
  151. ->excelSave($filename, $suffix, $path);
  152. $data = [
  153. 'name' => $filename . '.' . $suffix,
  154. 'status' => 1,
  155. 'path' => '/' . $_path
  156. ];
  157. return app('json')->success('ok', $data);
  158. }
  159. }