Gift.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. if(input('order_num')) $where[]= ['i.order_no','like','%'.input('order_num').'%'];
  50. $query = $this->_query($this->table)
  51. ->alias('i')
  52. ->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')
  53. ->join('store_member m','m.id = i.mid')
  54. ->join('store_member c','c.id = i.to_mid');
  55. if(!empty($where)) $query->where($where);
  56. if(input('coll_name')){
  57. $ids = Db::name('store_collection')->whereLike('name','%'.input('coll_name').'%')->column('id');
  58. $query->whereIn('c_id',$ids);
  59. }
  60. $query->dateBetween('over_time')->order('i.id desc')->page();
  61. }
  62. /**
  63. * 数据列表处理
  64. * @auth true
  65. * @menu true
  66. * @param array $data
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\ModelNotFoundException
  69. * @throws \think\exception\DbException
  70. */
  71. protected function _index_page_filter(&$data)
  72. {
  73. foreach ($data as $k=>&$v){
  74. $v['pro_info'] = json_decode($v['pro_info'],true);
  75. }
  76. }
  77. //删除货主
  78. public function remove()
  79. {
  80. $this->_save($this->table, ['status' => '3']);
  81. }
  82. public function edit(){
  83. $this->title = '编辑';
  84. $this->_form($this->table, 'form');
  85. }
  86. protected function _form_filter(&$data){
  87. if($this->request->isPost() && $this->request->action() == 'integral')
  88. {
  89. if($data['id']) {
  90. if($data['int_type'] == 6) {
  91. update_user_integral($data['id'],$data['int_num'],$data['int_type'],'后台增加');
  92. }else{
  93. update_user_integral($data['id'],$data['int_num'] * -1,$data['int_type'],'后台扣减');
  94. }
  95. }
  96. }
  97. if($this->request->isPost() && $this->request->action() == 'send')
  98. {
  99. if($data['id']) {
  100. $send_num = intval($data['send_num']);
  101. $coupon_id = $data['coupon_id'];
  102. if($send_num > 0){
  103. $coupon_info = Db::table('store_coupon_config')->find($coupon_id);
  104. $low_day = $coupon_info['low_day'];
  105. $coupon_data = [];
  106. for ($c = 1 ;$c <= $send_num ;$c++) {
  107. $coupon_data[]= [
  108. 'user_id' => $data['id'],
  109. 'low_day' =>$coupon_info['low_day'],
  110. 'lid' =>$coupon_id,
  111. 'money' =>$coupon_info['amount'],
  112. 'type' =>1,
  113. 'create_at'=> date('Y-m-d H:i:s'),
  114. 'past_at' => date('Y-m-d H:i:s',strtotime("+$low_day days"))
  115. ];
  116. }
  117. Db::table('user_coupon_list')->insertAll($coupon_data);
  118. }
  119. }
  120. }
  121. if($this->request->isPost() && $this->request->action() == 'crystal'){
  122. if($data['id']) {
  123. $change_crystal = intval($data['change_crystal']);
  124. $change_type = $data['int_type'];
  125. $mul = $change_type == 12 ? 1:-1;
  126. $msg = $change_type == 12 ? '后台充值':'后台扣减';
  127. $user_info = Db::table('store_member')->find($data['id']);
  128. $data['crystal'] = $user_info['crystal'] + $change_crystal*$mul;
  129. if( $data['crystal'] <0 || $data['crystal_cash']<0 ) $this->error('扣减数据数量有误!');
  130. if($change_crystal) crystal_log($data['id'],$change_crystal*$mul,$msg.'(元石)',$change_type);
  131. }
  132. }
  133. }
  134. }