Finance.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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' => 0, 'name' => '已完成提现总额'),
  101. array('className' => 'el-icon-s-goods', 'count' => 0, 'name' => '审核中总额'),
  102. );
  103. $list2 = array(
  104. array('className' => 'el-icon-s-goods', 'count' => 0, 'name' => '合伙分红总额'),
  105. array('className' => 'el-icon-s-goods', 'count' => 0, 'name' => '联创分红总额'),
  106. array('className' => 'el-icon-s-goods', 'count' => 0, 'name' => '股权分红总额'),
  107. );
  108. $res['right'][] = ['className' => 'el-icon-s-goods', 'count' => 0, 'name' => '提现总额', 'list' => $list1];
  109. $res['right'][] = ['className' => 'el-icon-s-goods', 'count' => 0, 'name' => '分红总额', 'list' => $list2];
  110. return app('json')->success('ok', $res);
  111. } catch (\Exception $e) {
  112. Db::name('log')->insert(['data' => '交易详情统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  113. return app('json')->fail('统计失败'. $e->getMessage());
  114. }
  115. }
  116. /**
  117. * 积分统计
  118. * @return mixed
  119. */
  120. public function integral_list(){
  121. try {
  122. $financeRepository = app()->make(FinanceRepository::class);
  123. $date = $financeRepository->integral_list();
  124. return app('json')->success($date);
  125. } catch (\Exception $e) {
  126. Db::name('log')->insert(['data' => '积分统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  127. return app('json')->fail('积分统计失败');
  128. }
  129. }
  130. /**
  131. * 京豆统计
  132. * @return mixed
  133. */
  134. public function jingdou_list(){
  135. try {
  136. $financeRepository = app()->make(FinanceRepository::class);
  137. $date = $financeRepository->jingdou_list();
  138. return app('json')->success($date);
  139. } catch (\Exception $e) {
  140. Db::name('log')->insert(['data' => '京豆统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  141. return app('json')->fail('京豆统计失败');
  142. }
  143. }
  144. /**
  145. * 贡献值统计
  146. * @return mixed
  147. */
  148. public function contribute_list(){
  149. try {
  150. $financeRepository = app()->make(FinanceRepository::class);
  151. $date = $financeRepository->contribute_list();
  152. return app('json')->success($date);
  153. } catch (\Exception $e) {
  154. Db::name('log')->insert(['data' => '贡献值统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  155. return app('json')->fail('贡献值统计失败');
  156. }
  157. }
  158. /**
  159. * 复购金统计
  160. * @return mixed
  161. */
  162. public function fugou_list(){
  163. try {
  164. $financeRepository = app()->make(FinanceRepository::class);
  165. $date = $financeRepository->fugou_list();
  166. return app('json')->success($date);
  167. } catch (\Exception $e) {
  168. Db::name('log')->insert(['data' => '复购金统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  169. return app('json')->fail('复购金统计失败');
  170. }
  171. }
  172. /**
  173. * 红包统计
  174. * @return mixed
  175. */
  176. public function hongbao_list(){
  177. try {
  178. $financeRepository = app()->make(FinanceRepository::class);
  179. $date = $financeRepository->hongbao_list();
  180. return app('json')->success($date);
  181. } catch (\Exception $e) {
  182. Db::name('log')->insert(['data' => '红包统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  183. return app('json')->fail('红包统计失败');
  184. }
  185. }
  186. /**
  187. * VR统计
  188. * @return mixed
  189. */
  190. public function vr_list(){
  191. try {
  192. $financeRepository = app()->make(FinanceRepository::class);
  193. $date = $financeRepository->vr_list();
  194. return app('json')->success($date);
  195. } catch (\Exception $e) {
  196. Db::name('log')->insert(['data' => 'VR统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  197. return app('json')->fail('VR统计失败');
  198. }
  199. }
  200. /**
  201. * PV统计
  202. * @return mixed
  203. */
  204. public function pv_list(){
  205. try {
  206. $financeRepository = app()->make(FinanceRepository::class);
  207. $date = $financeRepository->pv_list();
  208. return app('json')->success($date);
  209. } catch (\Exception $e) {
  210. Db::name('log')->insert(['data' => 'PV统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  211. return app('json')->fail('PV统计失败' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】');
  212. }
  213. }
  214. /**
  215. * 商户分润统计
  216. * @return mixed
  217. */
  218. public function fenrun_list(){
  219. try {
  220. $financeRepository = app()->make(FinanceRepository::class);
  221. $date = $financeRepository->fenrun_list();
  222. return app('json')->success($date);
  223. } catch (\Exception $e) {
  224. Db::name('log')->insert(['data' => '商户分润统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  225. return app('json')->fail('商户分润统计失败' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】');
  226. }
  227. }
  228. /**
  229. * 佣金统计
  230. * @return mixed
  231. */
  232. public function user_bill()
  233. {
  234. try {
  235. $financeRepository = app()->make(FinanceRepository::class);
  236. $date = $financeRepository->user_bill();
  237. return app('json')->success($date);
  238. } catch (\Exception $e) {
  239. Db::name('log')->insert(['data' => '佣金统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  240. return app('json')->fail('佣金统计失败');
  241. }
  242. }
  243. public function day_bill_list()
  244. {
  245. [$page, $limit] = $this->getPage();
  246. $where['mer_id'] = 0;
  247. $query = Db::name('enterprise_day_bill')->where($where);
  248. $date['count'] = $query->count();
  249. $date['list'] = $query->page($page, $limit)->order('day desc')->select();
  250. return app('json')->success($date);
  251. }
  252. public function month_bill_list()
  253. {
  254. [$page, $limit] = $this->getPage();
  255. $where['mer_id'] = 0;
  256. $query = Db::name('enterprise_month_bill')->field('id,month ,flow,expenditure,accounting')->where($where);
  257. $date['count'] = $query->count();
  258. $date['list'] = $query->page($page, $limit)->order('month desc')->select();
  259. return app('json')->success($date);
  260. }
  261. /**
  262. * 列表中的时间条件
  263. */
  264. public function date_where($Db, $where, $prefix = 'so.create_time', $field = '-')
  265. {
  266. if (!isset($where)) return $Db;
  267. switch ($where) {
  268. case 'today':
  269. $Db->whereBetween($prefix, [date('Y-m-d H:i:s', strtotime('today')), date('Y-m-d H:i:s', strtotime('tomorrow -1second'))]);
  270. break;
  271. case 'week':
  272. $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'))]);
  273. break;
  274. case 'month':
  275. $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'))]);
  276. break;
  277. case 'year':
  278. $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'))]);
  279. break;
  280. case 'yesterday':
  281. $Db->whereBetween($prefix, [date('Y-m-d H:i:s', strtotime('yesterday')), date('Y-m-d H:i:s', strtotime('today -1second'))]);
  282. break;
  283. case 'quarter':
  284. list($startTime, $endTime) = getMonth();
  285. $Db = $Db->where($prefix, '>', $startTime);
  286. $Db = $Db->where($prefix, '<', $endTime);
  287. break;
  288. case 'lately7':
  289. $Db = $Db->where($prefix, 'between', [date('Y-m-d', strtotime("-7 day")), date('Y-m-d H:i:s')]);
  290. break;
  291. case 'lately30':
  292. $Db = $Db->where($prefix, 'between', [date('Y-m-d', strtotime("-30 day")), date('Y-m-d H:i:s')]);
  293. break;
  294. default:
  295. if (strstr($where, $field) !== false) {
  296. list($startTime, $endTime) = explode($field, $where);
  297. if (strlen($startTime) == 4) {
  298. $Db->whereBetweenTime($prefix, date('Y-m-d H:i:s', strtotime($startTime)), date('Y-m-d H:i:s', strtotime($startTime . ' +1day -1second')));
  299. } else {
  300. if ($startTime == $endTime) {
  301. $Db = $Db->whereDay($prefix, $startTime);
  302. } else {
  303. $Db = $Db->where($prefix, '>', date('Y-m-d H:i:s', strtotime($startTime)));
  304. $Db = $Db->where($prefix, '<', date('Y-m-d H:i:s', strtotime($endTime)));
  305. }
  306. }
  307. }
  308. break;
  309. }
  310. return $Db;
  311. }
  312. }