Finance.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 integral_list(){
  34. try {
  35. $financeRepository = app()->make(FinanceRepository::class);
  36. $date = $financeRepository->integral_list();
  37. return app('json')->success($date);
  38. } catch (\Exception $e) {
  39. Db::name('log')->insert(['data' => '积分统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  40. return app('json')->fail('积分统计失败');
  41. }
  42. }
  43. /**
  44. * 京豆统计
  45. * @return mixed
  46. */
  47. public function jingdou_list(){
  48. try {
  49. $financeRepository = app()->make(FinanceRepository::class);
  50. $date = $financeRepository->jingdou_list();
  51. return app('json')->success($date);
  52. } catch (\Exception $e) {
  53. Db::name('log')->insert(['data' => '京豆统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  54. return app('json')->fail('京豆统计失败');
  55. }
  56. }
  57. /**
  58. * 贡献值统计
  59. * @return mixed
  60. */
  61. public function contribute_list(){
  62. try {
  63. $financeRepository = app()->make(FinanceRepository::class);
  64. $date = $financeRepository->contribute_list();
  65. return app('json')->success($date);
  66. } catch (\Exception $e) {
  67. Db::name('log')->insert(['data' => '贡献值统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  68. return app('json')->fail('贡献值统计失败');
  69. }
  70. }
  71. /**
  72. * 复购金统计
  73. * @return mixed
  74. */
  75. public function fugou_list(){
  76. try {
  77. $financeRepository = app()->make(FinanceRepository::class);
  78. $date = $financeRepository->fugou_list();
  79. return app('json')->success($date);
  80. } catch (\Exception $e) {
  81. Db::name('log')->insert(['data' => '复购金统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  82. return app('json')->fail('复购金统计失败');
  83. }
  84. }
  85. /**
  86. * 红包统计
  87. * @return mixed
  88. */
  89. public function hongbao_list(){
  90. try {
  91. $financeRepository = app()->make(FinanceRepository::class);
  92. $date = $financeRepository->hongbao_list();
  93. return app('json')->success($date);
  94. } catch (\Exception $e) {
  95. Db::name('log')->insert(['data' => '红包统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  96. return app('json')->fail('红包统计失败');
  97. }
  98. }
  99. /**
  100. * VR统计
  101. * @return mixed
  102. */
  103. public function vr_list(){
  104. try {
  105. $financeRepository = app()->make(FinanceRepository::class);
  106. $date = $financeRepository->vr_list();
  107. return app('json')->success($date);
  108. } catch (\Exception $e) {
  109. Db::name('log')->insert(['data' => 'VR统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  110. return app('json')->fail('VR统计失败');
  111. }
  112. }
  113. /**
  114. * 佣金统计
  115. * @return mixed
  116. */
  117. public function user_bill()
  118. {
  119. try {
  120. $financeRepository = app()->make(FinanceRepository::class);
  121. $date = $financeRepository->user_bill();
  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 transaction_overview()
  133. {
  134. try {
  135. $type = input('type', 1);
  136. $day = input('day', '');
  137. $mer_id = $this->request->merId();
  138. $financeRepository = app()->make(FinanceRepository::class);
  139. $arr = $financeRepository->jieyu($type,$day,$mer_id);
  140. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['yingyemoney']), 'name' => '营业总额'];
  141. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['ruzhang']), 'name' => '入账总额'];
  142. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['shouyi']), 'name' => '佣金奖励总额'];
  143. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['jieyu']), 'name' => '结余总额'];
  144. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['hf_fee_amt']), 'name' => '汇付通道服务费金额'];
  145. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['integral']), 'name' => '积分总数'];
  146. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['tixinan']), 'name' => '提现支出总额'];
  147. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['yanglao']), 'name' => '养老金总额'];
  148. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['gongxian']), 'name' => '贡献值总额'];
  149. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['jingdou']), 'name' => '京豆总额'];
  150. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['hongbao']), 'name' => '红包总额'];
  151. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['fugou']), 'name' => '复购金总额'];
  152. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['vr']), 'name' => 'VR总额'];
  153. return app('json')->success('ok', $data);
  154. } catch (\Exception $e) {
  155. Db::name('log')->insert(['data' => '交易详情统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  156. return app('json')->fail('统计失败'. $e->getMessage());
  157. }
  158. }
  159. public function day_bill_list()
  160. {
  161. [$page, $limit] = $this->getPage();
  162. $where['mer_id'] = 0;
  163. $query = Db::name('enterprise_day_bill')->where($where);
  164. $date['count'] = $query->count();
  165. $date['list'] = $query->page($page, $limit)->order('day desc')->select();
  166. return app('json')->success($date);
  167. }
  168. public function month_bill_list()
  169. {
  170. [$page, $limit] = $this->getPage();
  171. $where['mer_id'] = 0;
  172. $query = Db::name('enterprise_month_bill')->field('id,month ,flow,expenditure,accounting')->where($where);
  173. $date['count'] = $query->count();
  174. $date['list'] = $query->page($page, $limit)->order('month desc')->select();
  175. return app('json')->success($date);
  176. }
  177. /**
  178. * 列表中的时间条件
  179. */
  180. public function date_where($Db, $where, $prefix = 'so.create_time', $field = '-')
  181. {
  182. if (!isset($where)) return $Db;
  183. switch ($where) {
  184. case 'today':
  185. $Db->whereBetween($prefix, [date('Y-m-d H:i:s', strtotime('today')), date('Y-m-d H:i:s', strtotime('tomorrow -1second'))]);
  186. break;
  187. case 'week':
  188. $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'))]);
  189. break;
  190. case 'month':
  191. $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'))]);
  192. break;
  193. case 'year':
  194. $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'))]);
  195. break;
  196. case 'yesterday':
  197. $Db->whereBetween($prefix, [date('Y-m-d H:i:s', strtotime('yesterday')), date('Y-m-d H:i:s', strtotime('today -1second'))]);
  198. break;
  199. case 'quarter':
  200. list($startTime, $endTime) = getMonth();
  201. $Db = $Db->where($prefix, '>', $startTime);
  202. $Db = $Db->where($prefix, '<', $endTime);
  203. break;
  204. case 'lately7':
  205. $Db = $Db->where($prefix, 'between', [date('Y-m-d', strtotime("-7 day")), date('Y-m-d H:i:s')]);
  206. break;
  207. case 'lately30':
  208. $Db = $Db->where($prefix, 'between', [date('Y-m-d', strtotime("-30 day")), date('Y-m-d H:i:s')]);
  209. break;
  210. default:
  211. if (strstr($where, $field) !== false) {
  212. list($startTime, $endTime) = explode($field, $where);
  213. if (strlen($startTime) == 4) {
  214. $Db->whereBetweenTime($prefix, date('Y-m-d H:i:s', strtotime($startTime)), date('Y-m-d H:i:s', strtotime($startTime . ' +1day -1second')));
  215. } else {
  216. if ($startTime == $endTime) {
  217. $Db = $Db->whereDay($prefix, $startTime);
  218. } else {
  219. $Db = $Db->where($prefix, '>', date('Y-m-d H:i:s', strtotime($startTime)));
  220. $Db = $Db->where($prefix, '<', date('Y-m-d H:i:s', strtotime($endTime)));
  221. }
  222. }
  223. }
  224. break;
  225. }
  226. return $Db;
  227. }
  228. }