Fund.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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\allwin\controller;
  9. use app\allwin\model\Fund as FundModel;
  10. use app\allwin\model\FundBill;
  11. use app\allwin\model\CouponSubsidize;
  12. use app\allwin\model\Coupon;
  13. class Fund extends Common{
  14. public $mini_program = [];
  15. public function initialize() {
  16. parent::initialize();
  17. $this->assign('pathMaps',[['name'=>'采购基金','url'=>url("fund/index")]]);
  18. }
  19. /**
  20. * 采购基金
  21. * @return void
  22. */
  23. public function index(int $types = 0){
  24. $fund = FundModel::where($this->mini_program)->find();
  25. $counts = [];
  26. if(empty($fund)){
  27. $counts['balance'] = 0;
  28. $counts['subsidize'] = 0;
  29. $counts['subsidize_num'] = 0;
  30. }else{
  31. $counts['balance'] = $fund->balance;
  32. $counts['subsidize'] = $fund->subsidize;
  33. $counts['subsidize_num'] = $fund->subsidize_num;
  34. }
  35. $view['fund'] = $counts;
  36. if($types <= 1){
  37. $view['bill'] = FundBill::where($this->mini_program)->where(['types' => $types])->order('id desc')->paginate(10,false,['query'=>['types' => $types]]);
  38. }else{
  39. $view['bill'] = CouponSubsidize::with('coupon')->where($this->mini_program)->order('id desc')->paginate(10,false,['query'=>['types' => $types]]);
  40. }
  41. $view['types'] = $types;
  42. return view()->assign($view);
  43. }
  44. /**
  45. * 删除关联
  46. * @return void
  47. */
  48. public function delCoupon(int $id){
  49. $result = CouponSubsidize::where($this->mini_program)->where(['id' => $id])->delete();
  50. if($result){
  51. return json(['code'=>200,'msg'=>'操作成功']);
  52. }else{
  53. return json(['code'=>403,'msg'=>'删除失败']);
  54. }
  55. }
  56. /**
  57. * 关联优惠券
  58. * @return void
  59. */
  60. public function winCoupon(){
  61. if(request()->isAjax()){
  62. $ids = input('post.ids/s');
  63. if(empty($ids)){
  64. return json(['code'=>0,'msg'=>'请选择要关联的优惠券']);
  65. }
  66. $ida = ids($ids,true);
  67. $data = [];
  68. foreach ($ida as $key => $value) {
  69. $data[$key]['member_miniapp_id'] = $this->member_miniapp_id;
  70. $data[$key]['coupon_id'] = $value;
  71. $data[$key]['how_much'] = 0;
  72. }
  73. $result = CouponSubsidize::insertAll($data);
  74. if($result){
  75. return json(['code'=>302,'msg'=>'关联补贴优惠券成功','data' =>[]]);
  76. }else{
  77. return json(['code'=>0,'msg'=>'关联补贴优惠券失败']);
  78. }
  79. }else{
  80. $coupon = CouponSubsidize::where($this->mini_program)->field('coupon_id')->select()->toArray();
  81. $coupon_ids = [];
  82. if(!empty($coupon)){
  83. $coupon_ids = array_column($coupon,'coupon_id');
  84. }
  85. $view['lists'] = Coupon::where($this->mini_program)->whereNotIn('id',$coupon_ids)->order('size desc,id desc')->paginate(10);
  86. return view()->assign($view);
  87. }
  88. }
  89. /**
  90. * 排序
  91. */
  92. public function howmuch(){
  93. if(request()->isAjax()){
  94. $data = [
  95. 'sort' => input('post.sort/f'),
  96. 'id' => input('post.id/d'),
  97. ];
  98. $validate = $this->validate($data,'Coupon.sort');
  99. if(true !== $validate){
  100. return json(['code'=>0,'msg'=>$validate]);
  101. }
  102. $result = CouponSubsidize::where($this->mini_program)->where(['id' =>$data['id']])->update(['how_much' => $data['sort']]);
  103. if($result){
  104. return json(['code'=>200,'msg'=>'操作成功']);
  105. }else{
  106. return json(['code'=>0,'msg'=>'操作失败']);
  107. }
  108. }
  109. }
  110. }