Bank.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 客户收益管理
  7. */
  8. namespace app\popupshop\controller;
  9. use app\common\controller\Manage;
  10. use app\popupshop\model\BankBill;
  11. use app\popupshop\model\Bank as AppBank;
  12. use app\popupshop\model\BankCash;
  13. use app\popupshop\model\Config;
  14. use app\popupshop\model\BankInfo;
  15. use app\popupshop\model\Order;
  16. use app\popupshop\model\Sale;
  17. use app\popupshop\model\SaleOrder;
  18. use app\popupshop\model\SaleUser;
  19. use app\popupshop\model\Fees;
  20. use think\facade\Request;
  21. class Bank extends Manage
  22. {
  23. public function initialize()
  24. {
  25. parent::initialize();
  26. $this->assign('pathMaps', [['name'=>'客户收益','url'=>'javascript:;']]);
  27. }
  28. /**
  29. * 客户收益管理
  30. * @return void
  31. */
  32. public function index(int $types = 0){
  33. switch ($types) {
  34. case 1:
  35. $order = 'income_money desc';
  36. break;
  37. case 2:
  38. $order = 'due_money desc';
  39. break;
  40. case 3:
  41. $order = 'lack_money desc';
  42. break;
  43. case 4:
  44. $order = 'shop_money desc';
  45. break;
  46. default:
  47. $order = 'update_time desc';
  48. break;
  49. }
  50. $condition['member_miniapp_id'] = $this->member_miniapp_id;
  51. $view['list'] = AppBank::where($condition)->order($order)->paginate(20);
  52. $view['income_money'] = AppBank::where($condition)->sum('income_money');
  53. $view['due_money'] = AppBank::where($condition)->sum('due_money');
  54. $view['shop_money'] = AppBank::where($condition)->sum('shop_money');
  55. $view['lack_money'] = AppBank::where($condition)->sum('lack_money');
  56. $view['types'] = $types;
  57. return view()->assign($view);
  58. }
  59. /**
  60. * 客户收益记录
  61. * @return void
  62. */
  63. public function bill(int $input = 0){
  64. $starttime = Request::param('starttime',0);
  65. $endtime = Request::param('endtime',0);
  66. $where = [];
  67. $condition = [];
  68. $where[] = ['member_miniapp_id', '=', $this->member_miniapp_id];
  69. $condition[] = ['member_miniapp_id', '=', $this->member_miniapp_id];
  70. if($input){
  71. $where[] = ['user_id','=',$input];
  72. $condition[] = ['user_id','=',$input];
  73. }
  74. if(!empty($starttime) && !empty($endtime)){
  75. if($starttime > $endtime){
  76. $this->error('开始日期不能大于结束日期');
  77. }
  78. $where[] = ['update_time','>=',strtotime($starttime)];
  79. $where[] = ['update_time','<=',strtotime($endtime)];
  80. $condition[] = ['paid_time','>=',strtotime($starttime)];
  81. $condition[] = ['paid_time','<=',strtotime($endtime)];
  82. }
  83. $view['list'] = BankBill::where($where)->order('id desc')->paginate(20, false, ['query' => ['input' => $input, 'starttime' => $starttime, 'endtime' => $endtime]]);
  84. $view['count'] = BankBill::where($where)->count();
  85. $view['money'] = BankBill::where($where)->sum('money');
  86. $view['input'] = $input;
  87. $view['starttime'] = $starttime;
  88. $view['endtime'] = $endtime;
  89. return view()->assign($view);
  90. }
  91. /**
  92. * 客户提现
  93. */
  94. public function cash($types = 0){
  95. $keyword = trim(input('get.keyword','','htmlspecialchars'));
  96. $view['pending'] = BankCash::where(['member_miniapp_id' =>$this->member_miniapp_id,'state' => 0])->count();
  97. $view['pass'] = BankCash::where(['member_miniapp_id' =>$this->member_miniapp_id,'state' => 1])->count();
  98. $view['no_pass'] = BankCash::where(['member_miniapp_id' =>$this->member_miniapp_id,'state' => -1])->count();
  99. $condition['member_miniapp_id'] = $this->member_miniapp_id;
  100. if(!empty($keyword)){
  101. $condition['phone_uid'] = $keyword;
  102. }
  103. switch ($types) {
  104. case 1:
  105. $state = -1;
  106. break;
  107. case 2:
  108. $state = 1;
  109. break;
  110. default:
  111. $state = 0;
  112. break;
  113. }
  114. $condition['state'] = $state;
  115. $view['list'] = BankCash::where($condition)->order('id desc')->paginate(20,false,['query' => ['types' => $types]]);
  116. $view['money'] = BankCash::where($condition)->sum('money');
  117. $view['keyword'] = $keyword;
  118. $view['types'] = $types;
  119. return view()->assign($view);
  120. }
  121. /**
  122. * 导出到Excel
  123. */
  124. public function cashExcel($types = 0){
  125. header("Content-type: text/plain");
  126. header("Accept-Ranges: bytes");
  127. header("Content-type:application/vnd.ms-excel");
  128. header("Content-Disposition:attachment;filename=cash_".date('Y-m-d').".xls");
  129. header("Pragma: no-cache");
  130. header("Expires: 0");
  131. switch ($types) {
  132. case 1:
  133. $state = -1;
  134. break;
  135. case 2:
  136. $state = 1;
  137. break;
  138. default:
  139. $state = 0;
  140. break;
  141. }
  142. $condition['member_miniapp_id'] = $this->member_miniapp_id;
  143. $condition['state'] = $state;
  144. $view['list'] = BankCash::where($condition)->order('id desc')->select();
  145. $view['config'] = Config::where(['member_miniapp_id' => $this->member_miniapp_id])->find();
  146. return view()->assign($view);
  147. }
  148. /**
  149. * 充值积分
  150. * @return void
  151. */
  152. public function recharge(int $input){
  153. if(request()->isAjax()){
  154. $data = [
  155. 'user_id' => Request::param('uid/d'),
  156. 'types' => Request::param('types/d'),
  157. 'safepassword' => Request::param('safepassword/s'),
  158. 'shop_money' => Request::param('shop_money/f'),
  159. 'due_money' => Request::param('due_money/f'),
  160. 'miniapp_id' => $this->member_miniapp_id,
  161. ];
  162. $validate = $this->validate($data,'Bank.recharge');
  163. if(true !== $validate){
  164. return json(['code'=>0,'msg'=>$validate]);
  165. }
  166. //验证安全密码
  167. if(!password_verify(md5($data['safepassword']),$this->user->safe_password)) {
  168. return json(['code'=>0,'msg'=>"安全密码错误"]);
  169. }
  170. $due_money = money($data['due_money']);
  171. $shop_money = money($data['due_money']);
  172. if($data['types'] > 0){ //提取
  173. if($due_money > 0){
  174. AppBank::recharge($this->member_miniapp_id,$data['user_id'],-$due_money);
  175. BankBill::add($this->member_miniapp_id,$data['user_id'],-$due_money,'平台扣除余额'.-$due_money);
  176. }
  177. if($shop_money > 0){
  178. model('Bank')->rechargeShop($this->member_miniapp_id,$data['user_id'],-$data['shop_money']);
  179. BankBill::add($this->member_miniapp_id,$data['user_id'],-(intval($data['shop_money']*100)),'平台扣除积分'.-money($data['shop_money']));
  180. }
  181. }else{ //充值
  182. if($data['due_money'] > 0){
  183. model('Bank')->recharge($this->member_miniapp_id,$data['user_id'],$data['due_money']);
  184. BankBill::add($this->member_miniapp_id,$data['user_id'],intval($data['due_money']*100),'奖励应付积分'.money($data['due_money']));
  185. }
  186. if($data['shop_money'] > 0){
  187. model('Bank')->rechargeShop($this->member_miniapp_id,$data['user_id'],$data['shop_money']);
  188. BankBill::add($this->member_miniapp_id,$data['user_id'],intval($data['shop_money']*100),'奖励购物积分'.money($data['shop_money']));
  189. }
  190. }
  191. return json(['code'=>200,'msg'=>"充提操作成功"]);
  192. }else{
  193. if($this->user->parent_id){
  194. $this->error('无权限,非【创始人】身份');
  195. }
  196. $view['uid'] = $input;
  197. $view['info'] = model('SystemUser')->get(['member_miniapp_id' => $this->member_miniapp_id,'id' => $input]);
  198. return view()->assign($view);
  199. }
  200. }
  201. /**
  202. * 客户审核
  203. */
  204. public function cashpass(){
  205. $id = Request::param('id/d');
  206. if(request()->isAjax()){
  207. $data = [
  208. 'id' => $id,
  209. 'ispass' => Request::param('ispass/d',0),
  210. 'miniapp_id' => $this->member_miniapp_id,
  211. 'realmoney' => Request::param('realmoney/f')
  212. ];
  213. $validate = $this->validate($data,'Bank.cash');
  214. if(true !== $validate){
  215. return json(['code'=>0,'msg'=>$validate]);
  216. }
  217. $result = AppBank::isPass($data);
  218. return json($result);
  219. }else{
  220. $cash = BankCash::where(['member_miniapp_id' => $this->member_miniapp_id,'id' => $id])->find();
  221. if(empty($cash)){
  222. $this->error('未找到到所属内容');
  223. }
  224. $config = Config::where(['member_miniapp_id' => $this->member_miniapp_id])->find();
  225. $view['yescash'] = money($cash->money-$cash->money*$config->tax/100);
  226. $view['config'] = $config;
  227. $view['cash'] = $cash;
  228. $view['bankinfo'] = BankInfo::where(['member_miniapp_id' => $this->member_miniapp_id,'user_id' => $cash->user_id])->find();
  229. $view['bank'] = AppBank::where(['member_miniapp_id' => $this->member_miniapp_id,'user_id' => $cash->user_id])->find();
  230. return view()->assign($view);
  231. }
  232. }
  233. /**
  234. * @param int $types
  235. * @return \think\response\View
  236. * @throws \think\exception\DbException
  237. * 订单统计
  238. */
  239. public function statistics(){
  240. $starttime = Request::param('starttime/s');
  241. $endtime = Request::param('endtime/s');
  242. $condition[] = ['member_miniapp_id', '=', $this->member_miniapp_id];
  243. $where[] = ['member_miniapp_id', '=', $this->member_miniapp_id];
  244. if ($starttime) {
  245. $condition[] = ['update_time', '>=', strtotime($starttime)];
  246. $where[] = ['paid_time', '>=', strtotime($starttime)];
  247. }
  248. if ($endtime) {
  249. $condition[] = ['update_time', '<=', strtotime($endtime)];
  250. $where[] = ['paid_time', '<=', strtotime($endtime)];
  251. }
  252. //商城统计
  253. $view['shop_count'] = Order::where($where)->where(['paid_at' => 1])->count(); //总数量
  254. $view['shop_no_express'] = Order::where($where)->where(['paid_at' => 1, 'express_status' => 0])->count(); //待发货
  255. $view['shop_express'] = $view['shop_count'] - $view['shop_no_express']; //已发货
  256. $view['shop_payment'] = Order::where($where)->where(['paid_at' => 1])->sum('order_amount'); //总金额
  257. //活动订单
  258. $view['event_count'] = SaleOrder::where($where)->where(['paid_at' => 1])->count(); //总数量
  259. $view['event_no_express'] = SaleOrder::where($where)->where(['paid_at' => 1, 'express_status' => 0])->count(); //待发货
  260. $view['event_express'] = SaleOrder::where($where)->where(['paid_at' => 0, 'express_status' => 0])->count(); //已发货
  261. $view['event_payment'] = SaleOrder::where($where)->where(['paid_at' => 1])->sum('order_amount'); //总金额
  262. //寄卖统计
  263. $view['user_count'] = SaleUser::where($condition)->count();
  264. $view['user_pay_count'] = SaleUser::where($condition)->where(['is_rebate' => 1,'is_out' => 0])->count(); //已成交
  265. $view['user_pay_no_count'] = SaleUser::where($condition)->where(['is_rebate' => 0,'is_out' => 0])->count(); //未上架
  266. $view['user_money'] = SaleUser::where($condition)->sum('rebate'); //利润价
  267. //活动商品
  268. $view['sale_count'] = Sale::where($condition)->count(); //寄卖数量
  269. $view['sale_pay_count'] = Sale::where($condition)->where(['is_pay' => 1,'is_out' => 0])->count();
  270. $view['sale_pay_no_count'] = Sale::where($condition)->where(['is_pay' => 0,'is_out' => 0])->count();
  271. $view['sale_pay'] = Sale::where($condition)->where(['is_pay' => 1,'is_out' => 0])->sum('user_sale_price');
  272. $view['starttime'] = $starttime;
  273. $view['endtime'] = $endtime;
  274. return view()->assign($view);
  275. }
  276. /**
  277. * @param int $types
  278. * @return \think\response\View
  279. * @throws \think\exception\DbException
  280. * 财务统计
  281. */
  282. public function bankcount(){
  283. $starttime = Request::param('starttime/s');
  284. $endtime = Request::param('endtime/s');
  285. $condition[] = ['member_miniapp_id', '=', $this->member_miniapp_id];
  286. $view['income_money'] = AppBank::where($condition)->sum('income_money'); //累计流水
  287. $view['due_money'] = AppBank::where($condition)->sum('due_money'); //应付金额
  288. $view['shop_money'] = AppBank::where($condition)->sum('shop_money'); //购物积分
  289. $view['lack_money'] = AppBank::where($condition)->sum('lack_money'); //锁定金额
  290. $where[] = ['member_miniapp_id', '=', $this->member_miniapp_id];
  291. if ($starttime) {
  292. $condition[] = ['update_time', '>=', strtotime($starttime)];
  293. $where[] = ['paid_time', '>=', strtotime($starttime)];
  294. }
  295. if ($endtime) {
  296. $condition[] = ['update_time', '<=', strtotime($endtime)];
  297. $where[] = ['paid_time', '<=', strtotime($endtime)];
  298. }
  299. $view['apply_money'] = BankCash::where(['state' => 0])->sum('money'); //待审
  300. $view['apply_pass_money'] = BankCash::where(['state' => 1])->sum('money'); //已通过
  301. //金额
  302. $view['transaction_money'] = BankBill::where($condition)->sum('money');
  303. $view['user_money'] = SaleUser::where($condition)->where(['is_rebate' => 0,'is_out' => 0])->sum('user_price'); //用户利润价
  304. $view['cost'] = Fees::where($condition)->sum('cost'); //成交总价
  305. $view['fees'] = Fees::where($condition)->sum('fees'); //服务费
  306. $view['tax'] = Fees::where($condition)->sum('tax'); //平台费
  307. $view['starttime'] = $starttime;
  308. $view['endtime'] = $endtime;
  309. return view()->assign($view);
  310. }
  311. }