Finance.php 13 KB

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