Prize_set.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace Agent\Lib;
  3. use Dever;
  4. # 批量设置商品
  5. class Prize_set
  6. {
  7. public function __construct()
  8. {
  9. Dever::load('manage/auth.init');
  10. }
  11. # 获取商品列表
  12. public function goods_api()
  13. {
  14. $id = Dever::input('prize_id', 1);
  15. return Dever::load('agent/lib/set')->getData($id);
  16. }
  17. # 设置商品
  18. public function home_api()
  19. {
  20. $data = array();
  21. $data['link'] = Dever::decode(Dever::input('refer'));
  22. $data['prize_id'] = Dever::input('id', 1);
  23. Dever::setInput('prize_id', $data['prize_id']);
  24. $data['host'] = Dever::url('lib/prize_set.home?id=' . $data['prize_id'], 'agent');
  25. $data['url'] = Dever::url('lib/prize_set.goods?prize_id=' . $data['prize_id'], 'agent');
  26. $data['submit'] = Dever::url('lib/prize_set.action_commit?json=1', 'agent');
  27. return Dever::render('setPrizeGoods', $data);
  28. }
  29. # 设置
  30. public function action_commit_api()
  31. {
  32. $goods = Dever::input('goods');
  33. if (!$goods) {
  34. Dever::alert('请传入商品');
  35. }
  36. $goods = Dever::json_decode($goods);
  37. $prize_id = Dever::input('prize_id');
  38. $where['option_prize_id'] = $prize_id;
  39. $where['set_state'] = 2;
  40. Dever::db('setting/prize_goods')->updates($where);
  41. foreach ($goods as $k => $v) {
  42. $type = 1;
  43. $type_id = $k;
  44. $sku_id = -1;
  45. if (strstr($k, '_')) {
  46. $temp = explode('_', $k);
  47. $type_id = $temp[0];
  48. $type = $temp[1];
  49. } elseif (strstr($k, '-')) {
  50. $temp = explode('-', $k);
  51. $type_id = $temp[0];
  52. $sku_id = $temp[1];
  53. }
  54. if ($v['total'] <= 0) {
  55. continue;
  56. }
  57. $w = array();
  58. $w['type'] = $type;
  59. $w['type_id'] = $type_id;
  60. $w['prize_id'] = $prize_id;
  61. $w['sku_id'] = $sku_id;
  62. $info = Dever::db('setting/prize_goods')->one($w);
  63. if ($v['del'] == 2) {
  64. if ($info) {
  65. Dever::db('setting/prize_goods')->update(array('where_id' => $info['id'], 'state' => 2));
  66. }
  67. } else {
  68. $w['num'] = $v['total'];
  69. if (!$info) {
  70. Dever::db('setting/prize_goods')->insert($w);
  71. } else {
  72. $w['where_id'] = $info['id'];
  73. $w['state'] = 1;
  74. Dever::db('setting/prize_goods')->update($w);
  75. }
  76. }
  77. }
  78. return 'reload';
  79. }
  80. }