GoodsCollect.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 GoodsCollect
  21. * @package app\user\controller
  22. */
  23. class GoodsCollect extends Controller
  24. {
  25. /**
  26. * 绑定数据表
  27. * @var string
  28. */
  29. protected $table = 'GoodsCollect';
  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. $this->source_arr = ['','购买','兑换','邀请','赠送'];
  44. if(input('hash_str')){
  45. $detail = Db::table('goods_collect')->where('hash_str',input('hash_str'))->find();
  46. $id = $detail['id'];
  47. $original_id =$detail['original_id'];
  48. if($original_id > 0){
  49. $query = $this->_query($this->table)
  50. ->alias('c')
  51. ->field('c.*,m.name as user_name,m.headimg,m.phone')
  52. ->join('store_member m','m.id = c.user_id','LEFT')
  53. ->where('original_id|c.id',$original_id)
  54. ->order('c.id asc')->page();
  55. }else{
  56. $query = $this->_query($this->table)
  57. ->alias('c')
  58. ->field('c.*,m.name as user_name,m.headimg,m.phone')
  59. ->join('store_member m','m.id = c.user_id','LEFT')
  60. ->where('c.id',$id)
  61. ->order('c.id asc')->page();
  62. }
  63. }else{
  64. $where = [];
  65. $where[]= ['c.status','=',1];
  66. if(input('goods_name')) $where[]= ['c.goods_name','like','%'.input('goods_name').'%'];
  67. if(input('user_name')) $where[]= ['m.name','like','%'.input('user_name').'%'];
  68. if(input('phone')) $where[]= ['m.phone','like','%'.input('phone').'%'];
  69. $query = $this->_query($this->table)
  70. ->alias('c')
  71. ->field('c.*,m.name as user_name,m.headimg,m.phone')
  72. ->join('store_member m','m.id = c.user_id','LEFT')
  73. ->where($where);
  74. $query->order('c.id desc')->page();
  75. }
  76. }
  77. /**
  78. * 数据列表处理
  79. * @auth true
  80. * @menu true
  81. * @param array $data
  82. * @throws \think\db\exception\DataNotFoundException
  83. * @throws \think\db\exception\ModelNotFoundException
  84. * @throws \think\exception\DbException
  85. */
  86. protected function _index_page_filter(&$data)
  87. {
  88. foreach ($data as $k=>&$v){
  89. }
  90. }
  91. //删除货主
  92. public function remove()
  93. {
  94. $this->_save($this->table, ['status' => '3']);
  95. }
  96. public function edit(){
  97. $this->title = '编辑';
  98. $this->_form($this->table, 'form');
  99. }
  100. protected function _form_filter(&$data){
  101. if($this->request->isPost() && $this->request->action() == 'integral')
  102. {
  103. if($data['id']) {
  104. if($data['int_type'] == 6) {
  105. update_user_integral($data['id'],$data['int_num'],$data['int_type'],'后台增加');
  106. }else{
  107. update_user_integral($data['id'],$data['int_num'] * -1,$data['int_type'],'后台扣减');
  108. }
  109. }
  110. }
  111. if($this->request->isPost() && $this->request->action() == 'send')
  112. {
  113. if($data['id']) {
  114. $send_num = intval($data['send_num']);
  115. $coupon_id = $data['coupon_id'];
  116. if($send_num > 0){
  117. $coupon_info = Db::table('store_coupon_config')->find($coupon_id);
  118. $low_day = $coupon_info['low_day'];
  119. $coupon_data = [];
  120. for ($c = 1 ;$c <= $send_num ;$c++) {
  121. $coupon_data[]= [
  122. 'user_id' => $data['id'],
  123. 'low_day' =>$coupon_info['low_day'],
  124. 'lid' =>$coupon_id,
  125. 'money' =>$coupon_info['amount'],
  126. 'type' =>1,
  127. 'create_at'=> date('Y-m-d H:i:s'),
  128. 'past_at' => date('Y-m-d H:i:s',strtotime("+$low_day days"))
  129. ];
  130. }
  131. Db::table('user_coupon_list')->insertAll($coupon_data);
  132. }
  133. }
  134. }
  135. if($this->request->isPost() && $this->request->action() == 'crystal'){
  136. if($data['id']) {
  137. $change_crystal = intval($data['change_crystal']);
  138. $change_type = $data['int_type'];
  139. $mul = $change_type == 12 ? 1:-1;
  140. $msg = $change_type == 12 ? '后台充值':'后台扣减';
  141. $user_info = Db::table('store_member')->find($data['id']);
  142. $data['crystal'] = $user_info['crystal'] + $change_crystal*$mul;
  143. if( $data['crystal'] <0 || $data['crystal_cash']<0 ) $this->error('扣减数据数量有误!');
  144. if($change_crystal) crystal_log($data['id'],$change_crystal*$mul,$msg.'(元石)',$change_type);
  145. }
  146. }
  147. }
  148. }