Нема описа
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\admin\controller;
  14. use think\Config;
  15. use think\Page;
  16. use think\Db;
  17. class Memgift extends Base
  18. {
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $functionLogic = new \app\common\logic\FunctionLogic;
  23. $functionLogic->validate_authorfile(2);
  24. // 积分兑换是否已在用
  25. $shopLogic = new \app\admin\logic\ShopLogic;
  26. $useFunc = $shopLogic->useFuncLogic();
  27. if (!in_array('memgift', $useFunc)) {
  28. $this->error('内置功能已废弃!');
  29. }
  30. //积分名称
  31. $score = getUsersConfigData('score');
  32. $this->score_name = $score['score_name'];
  33. $this->assign('score', $score);
  34. }
  35. //积分商品列表
  36. public function index()
  37. {
  38. $condition = ['is_del' => 0];
  39. // 获取到所有GET参数
  40. $param = input('param.');
  41. if (isset($param['status']) && is_numeric($param['status'])) {
  42. $condition['status'] = intval($param['status']);
  43. }
  44. if (!empty($param['price1']) && !empty($param['price2'])) {
  45. $condition['score'] = ['between', $param['price1'] . ',' . $param['price2']];
  46. } else if (!empty($param['price1'])) {
  47. $condition['score'] = ['egt', $param['price1']];
  48. } else if (!empty($param['price2'])) {
  49. $condition['score'] = ['elt', $param['price2']];
  50. }
  51. $count = Db::name('memgift')->alias('a')->where($condition)->count();// 查询满足要求的总记录数
  52. $Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  53. $list = Db::name('memgift')->field('a.*')
  54. ->alias('a')
  55. ->where($condition)
  56. ->order('a.sort_order desc')
  57. ->limit($Page->firstRow . ',' . $Page->listRows)
  58. ->select();
  59. foreach ($list as $key => $val) {
  60. $list[$key]['litpic'] = get_default_pic($val['litpic']); // 支持子目录
  61. }
  62. $show = $Page->show();// 分页显示输出
  63. $this->assign('page', $show);// 赋值分页输出
  64. $this->assign('list', $list);// 赋值数据集
  65. $this->assign('pager', $Page);// 赋值分页集
  66. return $this->fetch();
  67. }
  68. //添加礼物
  69. public function add()
  70. {
  71. if (IS_POST) {
  72. $post = input('post.');
  73. if ($post['type'] > 0){
  74. $post['type_id'] = $post['type'];
  75. $post['type'] = 2;
  76. }
  77. $post['add_time'] = getTime();
  78. $r = Db::name("memgift")->insert($post);
  79. if ($r !== false) {
  80. $this->success("添加成功", url("Memgift/index"));
  81. } else {
  82. $this->error("添加失败");
  83. }
  84. }
  85. $users_level = Db::name('users_type_manage')
  86. ->alias('a')
  87. ->join('users_level b','a.level_id = b.level_id','left')
  88. ->where(['a.lang'=>$this->admin_lang])
  89. ->order('sort_order asc')
  90. ->field('b.level_name,a.level_id,a.limit_id,a.type_id,a.type_name')
  91. ->select();
  92. $limit_arr = Config::get('global.admin_member_limit_arr');
  93. if (!empty($users_level)){
  94. foreach ($users_level as &$v){
  95. $v['level_name'] = $v['level_name'].'('.$limit_arr[$v['limit_id']]['limit_name'].')';
  96. }
  97. }
  98. $this->assign('users_level', $users_level);// 赋值分页集
  99. return $this->fetch();
  100. }
  101. //编辑礼物
  102. public function edit()
  103. {
  104. if (IS_POST) {
  105. $post = input('post.');
  106. $gift_id = intval($post['gift_id']);
  107. if ($post['type'] > 0){
  108. $post['type_id'] = $post['type'];
  109. $post['type'] = 2;
  110. }
  111. $post['update_time'] = getTime();
  112. $r = Db::name("memgift")->where(['gift_id' => $gift_id])->update($post);
  113. if ($r !== false) {
  114. $this->success("修改成功", url("Memgift/index"));
  115. } else {
  116. $this->error("修改失败");
  117. }
  118. }
  119. $gift_id = input('gift_id/d');
  120. $info = Db::name('memgift')->alias('a')->where(['gift_id' => $gift_id])->find();
  121. $users_level = Db::name('users_type_manage')
  122. ->alias('a')
  123. ->join('users_level b','a.level_id = b.level_id','left')
  124. ->where(['a.lang'=>$this->admin_lang])
  125. ->order('sort_order asc')
  126. ->field('b.level_name,a.level_id,a.limit_id,a.type_id,a.type_name')
  127. ->select();
  128. $limit_arr = Config::get('global.admin_member_limit_arr');
  129. if (!empty($users_level)){
  130. foreach ($users_level as &$v){
  131. $v['level_name'] = $v['level_name'].'('.$limit_arr[$v['limit_id']]['limit_name'].')';
  132. }
  133. }
  134. $this->assign('users_level', $users_level);
  135. $this->assign('info', $info);
  136. return $this->fetch();
  137. }
  138. //兑换列表
  139. public function gift_exchange_list()
  140. {
  141. $condition = [];
  142. // 获取到所有GET参数
  143. $param = input('param.');
  144. if (!empty($param['gift_id'])) {
  145. $condition['a.gift_id'] = $param['gift_id'];
  146. $syb = 1;
  147. $this->assign('syb', $syb);
  148. }
  149. $status = input('param.status/s', 0);
  150. if (!empty($status)) {
  151. if ($status != -1) {
  152. $condition['a.status'] = $status;
  153. } else {
  154. $condition['a.status'] = 0;
  155. }
  156. }
  157. $keywords = input('param.keywords/s', "");
  158. if (!empty($keywords)) {
  159. $condition['b.username|b.nickname'] = $keywords;
  160. }
  161. $count = Db::name('memgiftget')->alias('a')->join("users b", "a.users_id = b.users_id", 'left')->where($condition)->count();// 查询满足要求的总记录数
  162. $Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  163. $list = Db::name('memgiftget')->field('a.*,b.username,b.nickname,b.head_pic,b.sex,c.type')
  164. ->alias('a')
  165. ->join("users b", "a.users_id = b.users_id", 'left')
  166. ->join("memgift c", "a.gift_id = c.gift_id", 'left')
  167. ->where($condition)
  168. ->order('a.gid desc')
  169. ->limit($Page->firstRow . ',' . $Page->listRows)
  170. ->select();
  171. foreach ($list as $key => $val) {
  172. $list[$key]['litpic'] = get_default_pic($val['litpic']); // 支持子目录
  173. }
  174. $show = $Page->show();// 分页显示输出
  175. $this->assign('page', $show);// 赋值分页输出
  176. $this->assign('list', $list);// 赋值数据集
  177. $this->assign('pager', $Page);// 赋值分页集
  178. //统计
  179. $count = Db::name('memgiftget')->field('count(*) as count,status')->group('status')->getAllWithIndex('status');
  180. $this->assign('count', $count);
  181. return $this->fetch();
  182. }
  183. //积分商品发货、退货
  184. public function give()
  185. {
  186. $param = input('param.');
  187. $gid = !empty($param['gid']) ? $param['gid'] : '';
  188. $syb = !empty($param['syb']) ? $param['syb'] : '';
  189. $do = !empty($param['do']) ? $param['do'] : '';
  190. $row = Db::name("memgiftget")
  191. ->alias('g')
  192. ->field("g.*,m.username,t.stock")
  193. ->join("users m", "m.users_id=g.users_id", "left")
  194. ->join("memgift t", "t.gift_id=g.gift_id", "left")
  195. ->where(['g.gid' => $gid])->find();
  196. $users_id = $row['users_id'];
  197. $score = $row['score'];
  198. if ($do == 'give') { //发货
  199. Db::name('memgiftget')->where(["gid" => $gid])->update(['status' => 1]);
  200. Db::name('users_notice')->insert(['title'=>$this->score_name.'兑换商品发货','users_id'=>$users_id,'usernames'=>'','remark'=>'您的'.$this->score_name.'兑换商品发货啦,请注意查收~','add_time'=>getTime(),'update_time'=>getTime()]);
  201. if (!empty($syb) && $syb == 1) {
  202. $url = url('Memgift/gift_exchange_list', ['gift_id' => $row['gift_id']]);
  203. } else {
  204. $url = url('Memgift/gift_exchange_list');
  205. }
  206. $this->success("成功发货!已站内信通知会员", $url);
  207. } else { //退回
  208. $r = Db::name('users')->where(['users_id' => $users_id])->update(['scores' => Db::raw("scores+" . $score)]);
  209. if ($r !== false) {
  210. //日志记录
  211. $users = Db::name('users')->where('users_id', $users_id)->field('scores,devote')->find();
  212. $data = [
  213. 'users_id' => $users_id,
  214. 'info' => "{$this->score_name}兑换取消,{$this->score_name}退回,gid={$gid}",
  215. 'score' => '+' . $score,
  216. 'type' => 9,
  217. 'add_time' => getTime(),
  218. 'update_time' => getTime(),
  219. 'current_score' => $users['scores'],
  220. 'current_devote' => $users['devote'],
  221. ];
  222. Db::name('users_score')->insert($data);
  223. Db::name('memgift')->where(['gift_id' => $row['gift_id']])->update(['stock' => Db::raw("stock+1"),'gid' => 0]);
  224. Db::name('memgiftget')->where(['gid' => $gid])->update(['status' => 2]);
  225. if (!isset($next)) {
  226. Db::name('users_notice')->insert(['title'=>$this->score_name.'兑换商品取消发货','users_id'=>$users_id,'usernames'=>'','remark'=>'您的'.$this->score_name.'兑换商品已取消发货!','add_time'=>getTime(),'update_time'=>getTime()]);
  227. $this->success("成功取消发货!已站内信通知会员", url('Memgift/gift_exchange_list'));
  228. } else {
  229. $url = url('Memgift/del', ['next' => 'ok', 'gift_id' => $row['gift_id']]);
  230. echo "<script type='text/javascript'>location.href='{$url}';</script>";
  231. }
  232. }
  233. }
  234. }
  235. //重发
  236. public function again()
  237. {
  238. $param = input('param.');
  239. $gid = !empty($param['gid']) ? $param['gid'] : '';
  240. $gift_id = !empty($param['gift_id']) ? $param['gift_id'] : '';
  241. $r = Db::name("memgift")->where(['gift_id' => $gift_id])->update(['stock' => Db::raw("stock+1")]);
  242. if ($r !== false) {
  243. Db::name("memgiftget")->where(['gid' => $gid])->update(['status' => 3]);
  244. $this->success("重发成功,该商品库存已补充", url('Memgift/index'));
  245. } else {
  246. $this->error("出问题了!");
  247. }
  248. }
  249. //删除积分商品
  250. public function del()
  251. {
  252. $id_arr = input('del_id/a');
  253. $id_arr = eyIntval($id_arr);
  254. if (IS_POST && !empty($id_arr)) {
  255. $result = Db::name("memgift")->field("giftname")->where(['gift_id' => ['in', $id_arr]])->select();
  256. $name_list = get_arr_column($result, 'giftname');
  257. $r = Db::name("memgift")->where(['gift_id' => ['in', $id_arr]])->cache(true, null, "memgift")
  258. ->delete();
  259. if ($r !== false) {
  260. adminLog('删除区域:' . implode(',', $name_list));
  261. $this->success('删除成功');
  262. }
  263. }
  264. $this->error('删除失败');
  265. }
  266. }