Gift.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\user\controller;
  15. use library\Controller;
  16. use think\Db;
  17. use function GuzzleHttp\Psr7\build_query;
  18. /**
  19. * 转赠记录管理
  20. * Class Gift
  21. * @package app\user\controller
  22. */
  23. class Gift extends Controller
  24. {
  25. /**
  26. * 绑定数据表
  27. * @var string
  28. */
  29. protected $table = 'store_order_info';
  30. /**
  31. * 作品列表
  32. * @auth true
  33. * @menu true
  34. * @throws \think\Exception
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. * @throws \think\exception\DbException
  38. * @throws \think\exception\PDOException
  39. */
  40. public function index()
  41. {
  42. $this->title = '转赠列表';
  43. $where = [];
  44. $where[] = ['i.status','in','2,3'];
  45. // $where[]= ['c.status','=',1];
  46. //if(input('goods_name')) $where[]= ['c.goods_name','like','%'.input('goods_name').'%'];
  47. if(input('name')) $where[]= ['m.name|c.name','like','%'.input('name').'%'];
  48. if(input('phone')) $where[]= ['m.phone|c.phone','like','%'.input('phone').'%'];
  49. $query = $this->_query($this->table)
  50. ->alias('i')
  51. ->field('i.*,m.name as from_name,m.phone as from_phone,m.headimg as from_headimg,c.name as to_name,c.phone as to_phone,c.headimg as to_headimg')
  52. ->join('store_member m','m.id = i.mid')
  53. ->join('store_member c','c.id = i.to_mid');
  54. if(!empty($where)) $query->where($where);
  55. if(input('coll_name')){
  56. $ids = Db::name('store_collection')->whereLike('name','%'.input('coll_name').'%')->column('id');
  57. $query->whereIn('c_id',$ids);
  58. }
  59. $query->dateBetween('over_time')->order('i.id desc')->page();
  60. }
  61. /**
  62. * 数据列表处理
  63. * @auth true
  64. * @menu true
  65. * @param array $data
  66. * @throws \think\db\exception\DataNotFoundException
  67. * @throws \think\db\exception\ModelNotFoundException
  68. * @throws \think\exception\DbException
  69. */
  70. protected function _index_page_filter(&$data)
  71. {
  72. foreach ($data as $k=>&$v){
  73. $v['pro_info'] = json_decode($v['pro_info'],true);
  74. }
  75. }
  76. //删除货主
  77. public function remove()
  78. {
  79. $this->_save($this->table, ['status' => '3']);
  80. }
  81. public function edit(){
  82. $this->title = '编辑';
  83. $this->_form($this->table, 'form');
  84. }
  85. protected function _form_filter(&$data){
  86. if($this->request->isPost() && $this->request->action() == 'integral')
  87. {
  88. if($data['id']) {
  89. if($data['int_type'] == 6) {
  90. update_user_integral($data['id'],$data['int_num'],$data['int_type'],'后台增加');
  91. }else{
  92. update_user_integral($data['id'],$data['int_num'] * -1,$data['int_type'],'后台扣减');
  93. }
  94. }
  95. }
  96. if($this->request->isPost() && $this->request->action() == 'send')
  97. {
  98. if($data['id']) {
  99. $send_num = intval($data['send_num']);
  100. $coupon_id = $data['coupon_id'];
  101. if($send_num > 0){
  102. $coupon_info = Db::table('store_coupon_config')->find($coupon_id);
  103. $low_day = $coupon_info['low_day'];
  104. $coupon_data = [];
  105. for ($c = 1 ;$c <= $send_num ;$c++) {
  106. $coupon_data[]= [
  107. 'user_id' => $data['id'],
  108. 'low_day' =>$coupon_info['low_day'],
  109. 'lid' =>$coupon_id,
  110. 'money' =>$coupon_info['amount'],
  111. 'type' =>1,
  112. 'create_at'=> date('Y-m-d H:i:s'),
  113. 'past_at' => date('Y-m-d H:i:s',strtotime("+$low_day days"))
  114. ];
  115. }
  116. Db::table('user_coupon_list')->insertAll($coupon_data);
  117. }
  118. }
  119. }
  120. if($this->request->isPost() && $this->request->action() == 'crystal'){
  121. if($data['id']) {
  122. $change_crystal = intval($data['change_crystal']);
  123. $change_type = $data['int_type'];
  124. $mul = $change_type == 12 ? 1:-1;
  125. $msg = $change_type == 12 ? '后台充值':'后台扣减';
  126. $user_info = Db::table('store_member')->find($data['id']);
  127. $data['crystal'] = $user_info['crystal'] + $change_crystal*$mul;
  128. if( $data['crystal'] <0 || $data['crystal_cash']<0 ) $this->error('扣减数据数量有误!');
  129. if($change_crystal) crystal_log($data['id'],$change_crystal*$mul,$msg.'(元石)',$change_type);
  130. }
  131. }
  132. }
  133. }