Finance.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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('积分统计失败'.$e->getMessage());
  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('京豆统计失败'.$e->getMessage());
  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('贡献值统计失败'.$e->getMessage());
  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('复购金统计失败'.$e->getMessage());
  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('红包统计失败'.$e->getMessage());
  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统计失败'.$e->getMessage());
  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. $type = input('type', 1);
  135. $day = input('day', '');
  136. $mer_id = $this->request->merId();
  137. $financeRepository = app()->make(FinanceRepository::class);
  138. $arr = $financeRepository->jieyu($type,$day,$mer_id);
  139. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['yingyemoney']), 'name' => '营业总额'];
  140. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['ruzhang']), 'name' => '入账总额'];
  141. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['shouyi']), 'name' => '佣金奖励总额'];
  142. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['jieyu']), 'name' => '结余总额'];
  143. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['hf_fee_amt']), 'name' => '汇付通道服务费金额'];
  144. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['integral']), 'name' => '积分总数'];
  145. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['tixinan']), 'name' => '提现支出总额'];
  146. $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['yanglao']), 'name' => '养老金总额'];
  147. return app('json')->success('ok', $data);
  148. }
  149. public function day_bill_list()
  150. {
  151. [$page, $limit] = $this->getPage();
  152. $where['mer_id'] = 0;
  153. $query = Db::name('enterprise_day_bill')->where($where);
  154. $date['count'] = $query->count();
  155. $date['list'] = $query->page($page, $limit)->order('day desc')->select();
  156. return app('json')->success($date);
  157. }
  158. public function month_bill_list()
  159. {
  160. [$page, $limit] = $this->getPage();
  161. $where['mer_id'] = 0;
  162. $query = Db::name('enterprise_month_bill')->field('id,month ,flow,expenditure,accounting')->where($where);
  163. $date['count'] = $query->count();
  164. $date['list'] = $query->page($page, $limit)->order('month desc')->select();
  165. return app('json')->success($date);
  166. }
  167. /**
  168. * 列表中的时间条件
  169. */
  170. public function date_where($Db, $where, $prefix = 'so.create_time', $field = '-')
  171. {
  172. if (!isset($where)) return $Db;
  173. switch ($where) {
  174. case 'today':
  175. $Db->whereBetween($prefix, [date('Y-m-d H:i:s', strtotime('today')), date('Y-m-d H:i:s', strtotime('tomorrow -1second'))]);
  176. break;
  177. case 'week':
  178. $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'))]);
  179. break;
  180. case 'month':
  181. $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'))]);
  182. break;
  183. case 'year':
  184. $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'))]);
  185. break;
  186. case 'yesterday':
  187. $Db->whereBetween($prefix, [date('Y-m-d H:i:s', strtotime('yesterday')), date('Y-m-d H:i:s', strtotime('today -1second'))]);
  188. break;
  189. case 'quarter':
  190. list($startTime, $endTime) = getMonth();
  191. $Db = $Db->where($prefix, '>', $startTime);
  192. $Db = $Db->where($prefix, '<', $endTime);
  193. break;
  194. case 'lately7':
  195. $Db = $Db->where($prefix, 'between', [date('Y-m-d', strtotime("-7 day")), date('Y-m-d H:i:s')]);
  196. break;
  197. case 'lately30':
  198. $Db = $Db->where($prefix, 'between', [date('Y-m-d', strtotime("-30 day")), date('Y-m-d H:i:s')]);
  199. break;
  200. default:
  201. if (strstr($where, $field) !== false) {
  202. list($startTime, $endTime) = explode($field, $where);
  203. if (strlen($startTime) == 4) {
  204. $Db->whereBetweenTime($prefix, date('Y-m-d H:i:s', strtotime($startTime)), date('Y-m-d H:i:s', strtotime($startTime . ' +1day -1second')));
  205. } else {
  206. if ($startTime == $endTime) {
  207. $Db = $Db->whereDay($prefix, $startTime);
  208. } else {
  209. $Db = $Db->where($prefix, '>', date('Y-m-d H:i:s', strtotime($startTime)));
  210. $Db = $Db->where($prefix, '<', date('Y-m-d H:i:s', strtotime($endTime)));
  211. }
  212. }
  213. }
  214. break;
  215. }
  216. return $Db;
  217. }
  218. }