Reward_set.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace Agent\Lib;
  3. use Dever;
  4. # 批量设置商品
  5. class Reward_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('reward_give_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['reward_give_id'] = Dever::input('id', 1);
  23. Dever::setInput('reward_give_id', $data['reward_give_id']);
  24. $data['host'] = Dever::url('lib/reward_set.home?id=' . $data['reward_give_id'], 'agent');
  25. $data['url'] = Dever::url('lib/reward_set.goods?reward_give_id=' . $data['reward_give_id'], 'agent');
  26. $data['submit'] = Dever::url('lib/reward_set.action_commit?json=1', 'agent');
  27. return Dever::render('setRewardGoods', $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. $reward_give_id = Dever::input('reward_give_id');
  38. $where['option_reward_give_id'] = $reward_give_id;
  39. $where['set_state'] = 2;
  40. Dever::db('setting/role_reward_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['reward_give_id'] = $reward_give_id;
  61. $w['sku_id'] = $sku_id;
  62. $info = Dever::db('setting/role_reward_goods')->one($w);
  63. if ($v['del'] == 2) {
  64. if ($info) {
  65. Dever::db('setting/role_reward_goods')->update(array('where_id' => $info['id'], 'state' => 2));
  66. }
  67. } else {
  68. $w['num'] = $v['total'];
  69. if (!$info) {
  70. Dever::db('setting/role_reward_goods')->insert($w);
  71. } else {
  72. $w['where_id'] = $info['id'];
  73. $w['state'] = 1;
  74. Dever::db('setting/role_reward_goods')->update($w);
  75. }
  76. }
  77. }
  78. return 'reload';
  79. }
  80. }