Finance.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. * PV统计
  115. * @return mixed
  116. */
  117. public function pv_list(){
  118. try {
  119. $financeRepository = app()->make(FinanceRepository::class);
  120. $date = $financeRepository->pv_list();
  121. return app('json')->success($date);
  122. } catch (\Exception $e) {
  123. Db::name('log')->insert(['data' => 'PV统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  124. return app('json')->fail('PV统计失败' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】');
  125. }
  126. }
  127. /**
  128. * 商户分润统计
  129. * @return mixed
  130. */
  131. public function fenrun_list(){
  132. try {
  133. $financeRepository = app()->make(FinanceRepository::class);
  134. $date = $financeRepository->fenrun_list();
  135. return app('json')->success($date);
  136. } catch (\Exception $e) {
  137. Db::name('log')->insert(['data' => '商户分润统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  138. return app('json')->fail('商户分润统计失败' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】');
  139. }
  140. }
  141. /**
  142. * 佣金统计
  143. * @return mixed
  144. */
  145. public function user_bill()
  146. {
  147. try {
  148. $financeRepository = app()->make(FinanceRepository::class);
  149. $date = $financeRepository->user_bill();
  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 transaction_overview()
  161. {
  162. try {
  163. $type = input('type', 1);
  164. $day = input('day', '');
  165. $mer_id = $this->request->merId();
  166. $financeRepository = app()->make(FinanceRepository::class);
  167. $arr = $financeRepository->jieyu($type,$day,$mer_id);
  168. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['yingyemoney']), 'name' => '营业总额'];
  169. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['ruzhang']), 'name' => '入账总额'];
  170. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['shouyi']), 'name' => '佣金奖励总额'];
  171. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['jieyu']), 'name' => '结余总额'];
  172. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['hf_fee_amt']), 'name' => '汇付通道服务费金额'];
  173. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['integral']), 'name' => '积分总数'];
  174. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['tixinan']), 'name' => '提现支出总额'];
  175. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['yanglao']), 'name' => '养老金总额'];
  176. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['gongxian']), 'name' => '贡献值总额'];
  177. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['jingdou']), 'name' => '京豆总额'];
  178. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['hongbao']), 'name' => '红包总额'];
  179. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['fugou']), 'name' => '复购金总额'];
  180. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['vr']), 'name' => 'VR总额'];
  181. return app('json')->success('ok', $data);
  182. } catch (\Exception $e) {
  183. Db::name('log')->insert(['data' => '交易详情统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
  184. return app('json')->fail('统计失败'. $e->getMessage());
  185. }
  186. }
  187. public function day_bill_list()
  188. {
  189. [$page, $limit] = $this->getPage();
  190. $where['mer_id'] = 0;
  191. $query = Db::name('enterprise_day_bill')->where($where);
  192. $date['count'] = $query->count();
  193. $date['list'] = $query->page($page, $limit)->order('day desc')->select();
  194. return app('json')->success($date);
  195. }
  196. public function month_bill_list()
  197. {
  198. [$page, $limit] = $this->getPage();
  199. $where['mer_id'] = 0;
  200. $query = Db::name('enterprise_month_bill')->field('id,month ,flow,expenditure,accounting')->where($where);
  201. $date['count'] = $query->count();
  202. $date['list'] = $query->page($page, $limit)->order('month desc')->select();
  203. return app('json')->success($date);
  204. }
  205. /**
  206. * 列表中的时间条件
  207. */
  208. public function date_where($Db, $where, $prefix = 'so.create_time', $field = '-')
  209. {
  210. if (!isset($where)) return $Db;
  211. switch ($where) {
  212. case 'today':
  213. $Db->whereBetween($prefix, [date('Y-m-d H:i:s', strtotime('today')), date('Y-m-d H:i:s', strtotime('tomorrow -1second'))]);
  214. break;
  215. case 'week':
  216. $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'))]);
  217. break;
  218. case 'month':
  219. $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'))]);
  220. break;
  221. case 'year':
  222. $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'))]);
  223. break;
  224. case 'yesterday':
  225. $Db->whereBetween($prefix, [date('Y-m-d H:i:s', strtotime('yesterday')), date('Y-m-d H:i:s', strtotime('today -1second'))]);
  226. break;
  227. case 'quarter':
  228. list($startTime, $endTime) = getMonth();
  229. $Db = $Db->where($prefix, '>', $startTime);
  230. $Db = $Db->where($prefix, '<', $endTime);
  231. break;
  232. case 'lately7':
  233. $Db = $Db->where($prefix, 'between', [date('Y-m-d', strtotime("-7 day")), date('Y-m-d H:i:s')]);
  234. break;
  235. case 'lately30':
  236. $Db = $Db->where($prefix, 'between', [date('Y-m-d', strtotime("-30 day")), date('Y-m-d H:i:s')]);
  237. break;
  238. default:
  239. if (strstr($where, $field) !== false) {
  240. list($startTime, $endTime) = explode($field, $where);
  241. if (strlen($startTime) == 4) {
  242. $Db->whereBetweenTime($prefix, date('Y-m-d H:i:s', strtotime($startTime)), date('Y-m-d H:i:s', strtotime($startTime . ' +1day -1second')));
  243. } else {
  244. if ($startTime == $endTime) {
  245. $Db = $Db->whereDay($prefix, $startTime);
  246. } else {
  247. $Db = $Db->where($prefix, '>', date('Y-m-d H:i:s', strtotime($startTime)));
  248. $Db = $Db->where($prefix, '<', date('Y-m-d H:i:s', strtotime($endTime)));
  249. }
  250. }
  251. }
  252. break;
  253. }
  254. return $Db;
  255. }
  256. }