Set.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. namespace Agent\Lib;
  3. use Dever;
  4. # 批量设置商品
  5. class Set
  6. {
  7. public function __construct()
  8. {
  9. Dever::load('manage/auth.init');
  10. }
  11. # 获取名额和体验卡
  12. public function getData($id)
  13. {
  14. $order_id = Dever::input('order_id');
  15. $mid = Dever::input('mid');
  16. $prize_id = Dever::input('prize_id');
  17. $reward_give_id = Dever::input('reward_give_id');
  18. $total = Dever::input('total', 1);
  19. $col = 'role_id';
  20. $table = 'setting/role_goods';
  21. $value = $id;
  22. if ($mid) {
  23. $col = 'mid';
  24. $table = 'agent/member_goods';
  25. $value = $mid;
  26. } elseif ($prize_id) {
  27. $col = 'prize_id';
  28. $table = 'setting/prize_goods';
  29. $value = $prize_id;
  30. } elseif ($reward_give_id) {
  31. $col = 'reward_give_id';
  32. $table = 'setting/role_reward_goods';
  33. $value = $reward_give_id;
  34. } elseif ($order_id) {
  35. $check = Dever::db('agent/order_goods')->find(array('order_id' => $order_id));
  36. if ($check) {
  37. $col = 'order_id';
  38. $table = 'agent/order_goods';
  39. $value = $order_id;
  40. }
  41. }
  42. $data = array();
  43. if (!$prize_id) {
  44. $prize = Dever::db('setting/prize')->select();
  45. if ($prize) {
  46. $data[0]['id'] = -1;
  47. $data[0]['name'] = '名额';
  48. $data[0]['price'] = 0;
  49. $data[0]['price_type'] = 2;
  50. $data[0]['select'] = 2;
  51. $data[0]['del'] = 1;
  52. $data[0]['total'] = 0;
  53. foreach ($prize as $k => $v) {
  54. $data[0]['children'][$k]['id'] = $v['id'] . '_3';
  55. $data[0]['children'][$k]['name'] = $v['name'];
  56. $data[0]['children'][$k]['price'] = $v['price'];
  57. $data[0]['children'][$k]['price_type'] = 2;
  58. $data[0]['children'][$k]['select'] = 2;
  59. $data[0]['children'][$k]['del'] = 1;
  60. $data[0]['children'][$k]['total'] = 0;
  61. $data[0]['children'][$k]['end'] = true;
  62. $w = array('type' => 3, 'type_id' => $v['id'], $col => $value);
  63. $give = Dever::input('give');
  64. if ($give) {
  65. $w['give'] = $give;
  66. }
  67. $info = Dever::db($table)->find($w);
  68. if ($info) {
  69. if ($table == 'agent/member_goods') {
  70. $info['num'] = $info['total_num'] - $info['sell_num'];
  71. //$info['num'] = $info['total_num'];
  72. }
  73. $data[0]['children'][$k]['select'] = 1;
  74. $data[0]['children'][$k]['total'] = $info['num'] * $total;
  75. }
  76. }
  77. }
  78. }
  79. $card = Dever::db('card/info')->getDataByType(array('type_id' => '1,4,5,6'));
  80. if ($card) {
  81. $data[1]['id'] = -2;
  82. $data[1]['name'] = '厨人E卡';
  83. $data[1]['price'] = 0;
  84. $data[1]['price_type'] = 2;
  85. $data[1]['select'] = 2;
  86. $data[1]['del'] = 1;
  87. $data[1]['total'] = 0;
  88. foreach ($card as $k => $v) {
  89. $data[1]['children'][$k]['id'] = $v['id'] . '_2';
  90. $data[1]['children'][$k]['name'] = $v['name'];
  91. if ($v['create_type'] == 3) {
  92. if ($mid) {
  93. $data[1]['children'][$k]['name'] .= '(自定义面值卡-已发卡无法更改价值)';
  94. } else {
  95. $data[1]['children'][$k]['name'] .= '(自定义面值卡-数量即百分比)';
  96. }
  97. }
  98. $data[1]['children'][$k]['price'] = $v['value'];
  99. $data[1]['children'][$k]['price_type'] = 2;
  100. $data[1]['children'][$k]['select'] = 2;
  101. $data[1]['children'][$k]['del'] = 1;
  102. $data[1]['children'][$k]['total'] = 0;
  103. $data[1]['children'][$k]['end'] = true;
  104. if ($table == 'agent/member_goods') {
  105. $w = array('type' => 2, 'type_id' => $v['id'], $col => $value);
  106. $give = Dever::input('give');
  107. if ($give) {
  108. $w['give'] = $give;
  109. }
  110. $info = Dever::db($table)->select($w);
  111. if ($info) {
  112. $num = 0;
  113. $data[1]['children'][$k]['price'] = 0;
  114. $sku_id = array();
  115. foreach ($info as $k1 => $v1) {
  116. $num += ($v1['total_num']-$v1['sell_num']);
  117. if ($v1['sku_id'] > 0) {
  118. $code = Dever::db('card/code')->find($v1['sku_id']);
  119. $data[1]['children'][$k]['price'] += $code['total_cash'];
  120. $sku_id[] = $v1['sku_id'];
  121. }
  122. }
  123. $data[1]['children'][$k]['id'] = $v['id'] . '-' . implode('i', $sku_id) . '_2';;
  124. $data[1]['children'][$k]['select'] = 1;
  125. $data[1]['children'][$k]['total'] = $num;
  126. }
  127. } else {
  128. $w = array('type' => 2, 'type_id' => $v['id'], $col => $value);
  129. $give = Dever::input('give');
  130. if ($give) {
  131. $w['give'] = $give;
  132. }
  133. $info = Dever::db($table)->find($w);
  134. if ($info) {
  135. $data[1]['children'][$k]['select'] = 1;
  136. if ($v['create_type'] == 3) {
  137. $data[1]['children'][$k]['total'] = $info['num'];
  138. } else {
  139. $data[1]['children'][$k]['total'] = $info['num'] * $total;
  140. }
  141. }
  142. }
  143. }
  144. }
  145. $data = array_merge($data, Dever::load('goods/lib/set.getGoodsList', $value, $col, $table, 'type_id'));
  146. return Dever::outDiy($data);
  147. }
  148. # 获取商品列表
  149. public function goods_api()
  150. {
  151. $id = Dever::input('id', 1);
  152. return $this->getData($id);
  153. }
  154. # 设置商品
  155. public function home_api()
  156. {
  157. $data = array();
  158. $data['link'] = Dever::decode(Dever::input('refer'));
  159. $data['role_id'] = Dever::input('id', 1);
  160. $data['give'] = Dever::input('give', 1);
  161. $data['host'] = Dever::url('lib/set.home?id=' . $data['role_id'], 'agent');
  162. $data['url'] = Dever::url('lib/set.goods?id=' . $data['role_id'] . '&give=' . $data['give'], 'agent');
  163. $data['search'] = Dever::db('setting/role_goods')->config['set']['give'];
  164. $data['submit'] = Dever::url('lib/set.action_commit?json=1', 'agent');
  165. return Dever::render('setGoods', $data);
  166. }
  167. # 设置生产能力
  168. public function action_commit_api()
  169. {
  170. $goods = Dever::input('goods');
  171. if (!$goods) {
  172. Dever::alert('请传入商品');
  173. }
  174. $goods = Dever::json_decode($goods);
  175. $role_id = Dever::input('role_id');
  176. $give = Dever::input('give');
  177. $where['option_role_id'] = $role_id;
  178. $where['option_give'] = $give;
  179. $where['set_state'] = 2;
  180. Dever::db('setting/role_goods')->updates($where);
  181. foreach ($goods as $k => $v) {
  182. $type = 1;
  183. $type_id = $k;
  184. $sku_id = -1;
  185. if (strstr($k, '_')) {
  186. $temp = explode('_', $k);
  187. $type_id = $temp[0];
  188. $type = $temp[1];
  189. } elseif (strstr($k, '-')) {
  190. $temp = explode('-', $k);
  191. $type_id = $temp[0];
  192. $sku_id = $temp[1];
  193. }
  194. if ($v['total'] <= 0) {
  195. continue;
  196. }
  197. $w = array();
  198. $w['type'] = $type;
  199. $w['type_id'] = $type_id;
  200. $w['role_id'] = $role_id;
  201. $w['sku_id'] = $sku_id;
  202. $w['give'] = $give;
  203. $info = Dever::db('setting/role_goods')->one($w);
  204. if ($v['del'] == 2) {
  205. if ($info) {
  206. Dever::db('setting/role_goods')->update(array('where_id' => $info['id'], 'state' => 2));
  207. }
  208. } else {
  209. $w['num'] = $v['total'];
  210. if (!$info) {
  211. Dever::db('setting/role_goods')->insert($w);
  212. } else {
  213. $w['where_id'] = $info['id'];
  214. $w['state'] = 1;
  215. Dever::db('setting/role_goods')->update($w);
  216. }
  217. }
  218. }
  219. return 'reload';
  220. }
  221. }