CustomScore.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php namespace App\Http\Controllers\Admin;
  2. use App\Http\Requests\Admin\CustomScore as Request;
  3. use App\Models\Custom;
  4. use App\Models\CustomScore as Model;
  5. use Illuminate\Support\Facades\DB;
  6. /**
  7. * 客户管理
  8. *
  9. * @author 刘相欣
  10. *
  11. */
  12. class CustomScore extends Auth{
  13. protected function _initialize(){
  14. parent::_initialize();
  15. $this->assign('breadcrumb1','积分管理');
  16. $this->assign('breadcrumb2','客户积分');
  17. }
  18. /**
  19. * 添加
  20. *
  21. * */
  22. public function incr(Request $request,Model $Model,Custom $Custom){
  23. // 接收参数
  24. $customUid = request('custom_uid',0);
  25. // 查询数据
  26. $custom = $Custom->getOne($customUid);
  27. // 提交
  28. if( request()->isMethod('post') ){
  29. // 验证参数
  30. $request->scene('incr')->validate();
  31. // 接收数据
  32. // 接收数据
  33. $incrScore = request('incr_score',0);
  34. // 组合数据,写入订单表,子表
  35. DB::beginTransaction();
  36. // 写入数据表
  37. $payId = $Model->trade($customUid,0,$incrScore,4,1);
  38. // 如果操作失败
  39. if( isset($payId['error']) ) {
  40. // 回滚
  41. DB::rollBack();
  42. // 结果提示
  43. return json_send(['code'=>'error','msg'=>$payId['error']]);
  44. }
  45. // 提交事务
  46. DB::commit();
  47. // 告知结果
  48. return json_send(['code'=>'success','msg'=>'增加成功','action'=>'add']);
  49. }
  50. // 如果不存在
  51. if( !$custom ) return $this->error('用户不存在');
  52. // 分配数据
  53. $this->assign('crumbs','增加积分');
  54. $this->assign('custom',$custom);
  55. // 加载模板
  56. return $this->fetch();
  57. }
  58. /**
  59. * 扣减
  60. *
  61. * */
  62. public function decr(Request $request,Model $Model,Custom $Custom){
  63. // 接收参数
  64. $customUid = request('custom_uid',0);
  65. // 查询数据
  66. $custom = $Custom->getOne($customUid);
  67. // 提交
  68. if( request()->isMethod('post') ){
  69. // 验证参数
  70. $request->scene('decr')->validate();
  71. // 接收数据
  72. $decrScore = request('decr_score',0);
  73. // 组合数据,写入订单表,子表
  74. DB::beginTransaction();
  75. // 写入数据表
  76. $payId = $Model->trade($customUid,0,($decrScore*-1),4,2);
  77. // 如果操作失败
  78. if( isset($payId['error']) ) {
  79. // 回滚
  80. DB::rollBack();
  81. // 结果提示
  82. return json_send(['code'=>'error','msg'=>$payId['error']]);
  83. }
  84. // 提交事务
  85. DB::commit();
  86. // 告知结果
  87. return json_send(['code'=>'success','msg'=>'扣减成功','action'=>'add']);
  88. }
  89. // 如果不存在
  90. if( !$custom ) return $this->error('用户不存在');
  91. // 分配数据
  92. $this->assign('crumbs','扣减积分');
  93. $this->assign('custom',$custom);
  94. // 加载模板
  95. return $this->fetch();
  96. }
  97. }