Finance.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <?php
  2. namespace app\controller\admin\finance;
  3. use app\common\repositories\finance\FinanceRepository;
  4. use app\controller\api\entropybarter\User;
  5. use crmeb\basic\BaseController;
  6. use think\facade\Db;
  7. class Finance extends BaseController
  8. {
  9. /**
  10. * 订单概况
  11. * @return mixed
  12. */
  13. public function order_overview()
  14. {
  15. $financeRepository = app()->make(FinanceRepository::class);
  16. $data = $financeRepository->order_overview();
  17. return app('json')->success('ok', $data);
  18. }
  19. /**
  20. * 用户概况
  21. * @return mixed
  22. */
  23. public function user_overview()
  24. {
  25. $financeRepository = app()->make(FinanceRepository::class);
  26. $data = $financeRepository->user_overview();
  27. return app('json')->success('ok', $data);
  28. }
  29. /**
  30. * 会员概况
  31. * @return mixed
  32. */
  33. public function member_overview()
  34. {
  35. $financeRepository = app()->make(FinanceRepository::class);
  36. $data = $financeRepository->member_overview();
  37. return app('json')->success('ok', $data);
  38. }
  39. /**
  40. * pv概况
  41. * @return mixed
  42. */
  43. public function pv_overview()
  44. {
  45. $financeRepository = app()->make(FinanceRepository::class);
  46. $data = $financeRepository->pv_overview();
  47. return app('json')->success('ok', $data);
  48. }
  49. /**
  50. * vr概况
  51. * @return mixed
  52. */
  53. public function vr_overview()
  54. {
  55. $financeRepository = app()->make(FinanceRepository::class);
  56. $data = $financeRepository->vr_overview();
  57. return app('json')->success('ok', $data);
  58. }
  59. /**
  60. * 积分概况
  61. * @return mixed
  62. */
  63. public function jifen_overview()
  64. {
  65. $financeRepository = app()->make(FinanceRepository::class);
  66. $data = $financeRepository->jifen_overview();
  67. return app('json')->success('ok', $data);
  68. }
  69. /**
  70. * 交易概况
  71. * @return mixed
  72. */
  73. public function transaction_overview()
  74. {
  75. try {
  76. $type = input('type', 1);
  77. $day = input('day', '');
  78. $mer_id = $this->request->merId();
  79. $financeRepository = app()->make(FinanceRepository::class);
  80. $arr = $financeRepository->jieyu($type,$day,$mer_id);
  81. // $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['yingyemoney']), 'name' => '营业总额'];
  82. // $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['ruzhang']), 'name' => '入账总额'];
  83. // $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['jieyu']), 'name' => '结余总额'];
  84. // $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['hf_fee_amt']), 'name' => '汇付通道服务费金额'];
  85. // $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['integral']), 'name' => '积分总数'];
  86. // $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['tixinan']), 'name' => '提现支出总额'];
  87. $data['one'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['yanglao']), 'name' => '养老金总额'];
  88. $data['one'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['shouyi']), 'name' => '佣金总额'];
  89. $data['one'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['suoke']), 'name' => '锁客收益总额'];
  90. $data['one'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['fugou']), 'name' => '复购金总额'];
  91. $data['one'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['hongbao']), 'name' => '红包总额'];
  92. $data['tow'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['jingdou']), 'name' => '京豆总额'];
  93. $data['tow'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['gongxian']), 'name' => '贡献值总额'];
  94. $data['tow'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['integral']), 'name' => '积分总额'];
  95. $data['tow'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['pv']), 'name' => 'PV总额'];
  96. $data['tow'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['vr']), 'name' => 'VR总额'];
  97. $res['left'] = $data;
  98. //底部大模块
  99. $list1 = array(
  100. array('className' => 'el-icon-s-goods', 'count' => $arr['extract_wancheng_count'], 'name' => '已完成提现总额'),
  101. array('className' => 'el-icon-s-goods', 'count' => $arr['extract_shenhezhong_count'], 'name' => '审核中总额'),
  102. );
  103. $list2 = array(
  104. array('className' => 'el-icon-s-goods', 'count' => $arr['hehuo'], 'name' => '合伙分红总额'),
  105. array('className' => 'el-icon-s-goods', 'count' => $arr['lianchuang'], 'name' => '联创分红总额'),
  106. array('className' => 'el-icon-s-goods', 'count' => $arr['guquan'], 'name' => '股权分红总额'),
  107. );
  108. $fenhong = bcadd($arr['hehuo'],bcadd($arr['lianchuang'],$arr['guquan'],2),2);
  109. $res['right'][] = ['className' => 'el-icon-s-goods', 'count' => bcadd($arr['extract_wancheng_count'],$arr['extract_shenhezhong_count'],2), 'name' => '提现总额', 'list' => $list1];
  110. $res['right'][] = ['className' => 'el-icon-s-goods', 'count' => $fenhong, 'name' => '分红总额', 'list' => $list2];
  111. return app('json')->success('ok', $res);
  112. } catch (\Exception $e) {
  113. Db::name('log')->insert(['data' => '交易详情统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  114. return app('json')->fail('统计失败'. $e->getMessage());
  115. }
  116. }
  117. /**
  118. * 积分统计
  119. * @return mixed
  120. */
  121. public function integral_list(){
  122. try {
  123. $financeRepository = app()->make(FinanceRepository::class);
  124. $date = $financeRepository->integral_list();
  125. return app('json')->success($date);
  126. } catch (\Exception $e) {
  127. Db::name('log')->insert(['data' => '积分统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  128. return app('json')->fail('积分统计失败');
  129. }
  130. }
  131. /**
  132. * 京豆统计
  133. * @return mixed
  134. */
  135. public function jingdou_list(){
  136. try {
  137. $financeRepository = app()->make(FinanceRepository::class);
  138. $date = $financeRepository->jingdou_list();
  139. return app('json')->success($date);
  140. } catch (\Exception $e) {
  141. Db::name('log')->insert(['data' => '京豆统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  142. return app('json')->fail('京豆统计失败');
  143. }
  144. }
  145. /**
  146. * 贡献值统计
  147. * @return mixed
  148. */
  149. public function contribute_list(){
  150. try {
  151. $financeRepository = app()->make(FinanceRepository::class);
  152. $date = $financeRepository->contribute_list();
  153. return app('json')->success($date);
  154. } catch (\Exception $e) {
  155. Db::name('log')->insert(['data' => '贡献值统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  156. return app('json')->fail('贡献值统计失败');
  157. }
  158. }
  159. /**
  160. * 复购金统计
  161. * @return mixed
  162. */
  163. public function fugou_list(){
  164. try {
  165. $financeRepository = app()->make(FinanceRepository::class);
  166. $date = $financeRepository->fugou_list();
  167. return app('json')->success($date);
  168. } catch (\Exception $e) {
  169. Db::name('log')->insert(['data' => '复购金统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  170. return app('json')->fail('复购金统计失败');
  171. }
  172. }
  173. /**
  174. * 红包统计
  175. * @return mixed
  176. */
  177. public function hongbao_list(){
  178. try {
  179. $financeRepository = app()->make(FinanceRepository::class);
  180. $date = $financeRepository->hongbao_list();
  181. return app('json')->success($date);
  182. } catch (\Exception $e) {
  183. Db::name('log')->insert(['data' => '红包统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  184. return app('json')->fail('红包统计失败');
  185. }
  186. }
  187. /**
  188. * VR统计
  189. * @return mixed
  190. */
  191. public function vr_list(){
  192. try {
  193. $financeRepository = app()->make(FinanceRepository::class);
  194. $date = $financeRepository->vr_list();
  195. return app('json')->success($date);
  196. } catch (\Exception $e) {
  197. Db::name('log')->insert(['data' => 'VR统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  198. return app('json')->fail('VR统计失败');
  199. }
  200. }
  201. /**
  202. * PV统计
  203. * @return mixed
  204. */
  205. public function pv_list(){
  206. try {
  207. $financeRepository = app()->make(FinanceRepository::class);
  208. $date = $financeRepository->pv_list();
  209. return app('json')->success($date);
  210. } catch (\Exception $e) {
  211. Db::name('log')->insert(['data' => 'PV统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  212. return app('json')->fail('PV统计失败' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】');
  213. }
  214. }
  215. /**
  216. * 商户分润统计
  217. * @return mixed
  218. */
  219. public function fenrun_list(){
  220. try {
  221. $financeRepository = app()->make(FinanceRepository::class);
  222. $date = $financeRepository->fenrun_list();
  223. return app('json')->success($date);
  224. } catch (\Exception $e) {
  225. Db::name('log')->insert(['data' => '商户分润统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  226. return app('json')->fail('商户分润统计失败' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】');
  227. }
  228. }
  229. /**
  230. * 佣金统计
  231. * @return mixed
  232. */
  233. public function user_bill()
  234. {
  235. try {
  236. $financeRepository = app()->make(FinanceRepository::class);
  237. $date = $financeRepository->user_bill();
  238. return app('json')->success($date);
  239. } catch (\Exception $e) {
  240. Db::name('log')->insert(['data' => '佣金统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  241. return app('json')->fail('佣金统计失败');
  242. }
  243. }
  244. public function day_bill_list()
  245. {
  246. [$page, $limit] = $this->getPage();
  247. $where['mer_id'] = 0;
  248. $query = Db::name('enterprise_day_bill')->where($where);
  249. $date['count'] = $query->count();
  250. $date['list'] = $query->page($page, $limit)->order('day desc')->select();
  251. return app('json')->success($date);
  252. }
  253. public function month_bill_list()
  254. {
  255. [$page, $limit] = $this->getPage();
  256. $where['mer_id'] = 0;
  257. $query = Db::name('enterprise_month_bill')->where($where);
  258. $date['count'] = $query->count();
  259. $date['list'] = $query->page($page, $limit)->order('month desc')->select();
  260. return app('json')->success($date);
  261. }
  262. /**
  263. * 列表中的时间条件
  264. */
  265. public function date_where($Db, $where, $prefix = 'so.create_time', $field = '-')
  266. {
  267. if (!isset($where)) return $Db;
  268. switch ($where) {
  269. case 'today':
  270. $Db->whereBetween($prefix, [date('Y-m-d H:i:s', strtotime('today')), date('Y-m-d H:i:s', strtotime('tomorrow -1second'))]);
  271. break;
  272. case 'week':
  273. $Db->whereBetween($prefix, [date('Y-m-d H:i:s', strtotime('this week 00:00:00')), date('Y-m-d H:i:s', strtotime('next week 00:00:00 -1second'))]);
  274. break;
  275. case 'month':
  276. $Db->whereBetween($prefix, [date('Y-m-d H:i:s', strtotime('first Day of this month 00:00:00')), date('Y-m-d H:i:s', strtotime('first Day of next month 00:00:00 -1second'))]);
  277. break;
  278. case 'year':
  279. $Db->whereBetween($prefix, [date('Y-m-d H:i:s', strtotime('this year 1/1')), date('Y-m-d H:i:s', strtotime('next year 1/1 -1second'))]);
  280. break;
  281. case 'yesterday':
  282. $Db->whereBetween($prefix, [date('Y-m-d H:i:s', strtotime('yesterday')), date('Y-m-d H:i:s', strtotime('today -1second'))]);
  283. break;
  284. case 'quarter':
  285. list($startTime, $endTime) = getMonth();
  286. $Db = $Db->where($prefix, '>', $startTime);
  287. $Db = $Db->where($prefix, '<', $endTime);
  288. break;
  289. case 'lately7':
  290. $Db = $Db->where($prefix, 'between', [date('Y-m-d', strtotime("-7 day")), date('Y-m-d H:i:s')]);
  291. break;
  292. case 'lately30':
  293. $Db = $Db->where($prefix, 'between', [date('Y-m-d', strtotime("-30 day")), date('Y-m-d H:i:s')]);
  294. break;
  295. default:
  296. if (strstr($where, $field) !== false) {
  297. list($startTime, $endTime) = explode($field, $where);
  298. if (strlen($startTime) == 4) {
  299. $Db->whereBetweenTime($prefix, date('Y-m-d H:i:s', strtotime($startTime)), date('Y-m-d H:i:s', strtotime($startTime . ' +1day -1second')));
  300. } else {
  301. if ($startTime == $endTime) {
  302. $Db = $Db->whereDay($prefix, $startTime);
  303. } else {
  304. $Db = $Db->where($prefix, '>', date('Y-m-d H:i:s', strtotime($startTime)));
  305. $Db = $Db->where($prefix, '<', date('Y-m-d H:i:s', strtotime($endTime)));
  306. }
  307. }
  308. }
  309. break;
  310. }
  311. return $Db;
  312. }
  313. }