Manage.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?php
  2. namespace Goods\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function search_api()
  7. {
  8. $table = 'goods/info';
  9. $keyword = Dever::input('keyword');
  10. $yes = Dever::input('yes');
  11. $where = array();
  12. $cate = Dever::input('cate');
  13. if ($cate) {
  14. $where['cate_id'] = $cate;
  15. }
  16. if ($yes) {
  17. $yes = Dever::db($table)->search(array('ids' => $yes));
  18. }
  19. if (!$keyword) {
  20. $where['limit'] = '0,50';
  21. $data = Dever::db($table)->search($where);
  22. } else {
  23. $where['name'] = $keyword;
  24. $data = Dever::db($table)->search($where);
  25. }
  26. $result = array();
  27. if ($yes) {
  28. foreach ($yes as $k => $v) {
  29. if (isset($data[$k])) {
  30. unset($data[$k]);
  31. }
  32. $yes[$k]['selected'] = 'selected';
  33. }
  34. $data = $yes + $data;
  35. $data = array_merge($data, array());
  36. } else {
  37. $data = array_merge($data, array());
  38. }
  39. if (!$data) {
  40. Dever::alert('暂无数据');
  41. }
  42. return $data;
  43. }
  44. /**
  45. * 更新信息
  46. *
  47. * @return mixed
  48. */
  49. public function infoUpdate($id, $name, $data)
  50. {
  51. # 更新分类id
  52. $category = Dever::param('category', $data);
  53. if ($category) {
  54. if (is_array($category)) {
  55. $category_id = end($category);
  56. $top_category_id = $category[0];
  57. if (isset($category[1])) {
  58. $second_category_id = $category[1];
  59. } else {
  60. $second_category_id = $category[0];
  61. }
  62. } else {
  63. $category_id = $category;
  64. $top_category_id = $category;
  65. $second_category_id = $category;
  66. }
  67. $update['top_category_id'] = $top_category_id;
  68. $update['second_category_id'] = $second_category_id;
  69. $update['category_id'] = $category_id;
  70. }
  71. $pic = Dever::param('pic', $data);
  72. $pic_cover = Dever::param('pic_cover', $data);
  73. if ($pic && !$pic_cover) {
  74. if (is_string($pic)) {
  75. $pic = explode(',', $pic);
  76. }
  77. $update['pic_cover'] = $pic[0];
  78. }
  79. if (isset($update)) {
  80. $update['where_id'] = $id;
  81. Dever::db('goods/info')->update($update);
  82. }
  83. }
  84. /**
  85. * 更新需求属性信息
  86. *
  87. * @return mixed
  88. */
  89. public function attrUpdate($id, $name, $data)
  90. {
  91. print_r($data);die;
  92. foreach ($data as $k => $v) {
  93. }
  94. }
  95. /**
  96. * 显示信息
  97. *
  98. * @return mixed
  99. */
  100. public function info($id)
  101. {
  102. $info = Dever::db('goods/info')->one($id);
  103. if ($info) {
  104. $table['编号'] = $info['id'];
  105. $table['标题'] = $info['name'];
  106. $table['分类'] = Dever::load("category/api.string", $info['category']);
  107. if ($info['pic_cover']) {
  108. $table['封面图'] = '<img src="'.$info['pic_cover'].'" width="150" />';
  109. }
  110. if ($info['shop_id'] > 0) {
  111. $shop = Dever::load('goods/shop-one', $info['shop_id']);
  112. $table['所属店铺'] = $shop['name'];
  113. }
  114. if ($info['brand_id'] > 0) {
  115. $brand = Dever::load('goods/brand-one', $info['brand_id']);
  116. $table['所属品牌'] = $brand['name'];
  117. }
  118. //$table['属性'] = $this->attrInfo($info);
  119. if ($info['cdate']) {
  120. $table['发布时间'] = date("Y-m-d H:i:s", $info['cdate']);
  121. }
  122. }
  123. return Dever::table($table);
  124. }
  125. private function attrInfo($info)
  126. {
  127. $table = array();
  128. $info = Info::init($info['top_category_id']);
  129. if ($info) {
  130. $info = $info->info($info, 'id');
  131. if ($info && isset($info['attr'])) {
  132. foreach ($info['attr'] as $k => $v) {
  133. $table[$v['name']] = $v['value_string'];
  134. }
  135. }
  136. }
  137. return Dever::table($table);
  138. }
  139. public function area($id, $name, $data)
  140. {
  141. # 不再执行syncone等后续操作
  142. Dever::config('base')->after = 1;
  143. $type = Dever::input('type');
  144. $area = Dever::param('area', $data);
  145. if ($area) {
  146. if (isset($area[2])) {
  147. $update['district_id'] = $area[2];
  148. }
  149. if (isset($area[1])) {
  150. $update['city_id'] = $area[1];
  151. }
  152. if (isset($area[0])) {
  153. $update['province_id'] = $area[0];
  154. }
  155. if (isset($update)) {
  156. $update['where_id'] = $id;
  157. Dever::db($type . '/info')->update($update);
  158. }
  159. }
  160. }
  161. public function skuConfig()
  162. {
  163. $data['action'] = Dever::url('goods/lib/manage.skuUp');
  164. $data['info_id'] = Dever::input('search_option_info_id');
  165. return $data;
  166. }
  167. public function skuUp_api()
  168. {
  169. $info_id = Dever::input('info_id');
  170. $attr = Dever::input('attr');
  171. $key = Dever::input('key');
  172. $price = Dever::input('price');
  173. $s_price = Dever::input('s_price');
  174. $num = Dever::input('num');
  175. if ($key) {
  176. foreach ($key as $k => $v) {
  177. if (isset($price[$k]) && $price[$k]) {
  178. $info = Dever::db('goods/info_sku')->one(array('key' => $v));
  179. $data['info_id'] = $info_id;
  180. $data['attr'] = $attr[$k];
  181. $data['key'] = $v;
  182. $data['price'] = $price[$k];
  183. $data['s_price'] = $s_price[$k];
  184. $data['num'] = $num[$k];
  185. if (!$info) {
  186. Dever::db('goods/info_sku')->insert($data);
  187. } else {
  188. $data['where_id'] = $info['id'];
  189. Dever::db('goods/info_sku')->update($data);
  190. }
  191. }
  192. }
  193. }
  194. Dever::out('yes');
  195. }
  196. public function skuInput()
  197. {
  198. $id = Dever::input('search_option_info_id');
  199. $sku = Dever::db('goods/info_sku')->getData(array('info_id' => $id));
  200. $info = Dever::db('goods/info')->one($id);
  201. $info = Info::init(-1)->info($info, 'list_reorder');
  202. if ($info['sell_attr']) {
  203. $head = '<thead><tr>';
  204. $body = '<tbody>';
  205. $option = array();
  206. foreach ($info['sell_attr'] as $k => $v) {
  207. $head .= '<th>'.$v['name'].'</th>';
  208. if (isset($v['option_sku'])) {
  209. $option[$k] = $v['option_sku'];
  210. }
  211. }
  212. $head .= '<th>原价</th>';
  213. $head .= '<th>现价</th>';
  214. $head .= '<th>库存</th>';
  215. $head .= '</tr></thead>';
  216. if ($option) {
  217. $option = Dever::cartesian($option);
  218. foreach ($option as $k => $v) {
  219. $body .= '<tr data-row="' .($k+1). '">';
  220. $key = $id = array();
  221. foreach ($v['name'] as $k1 => $v1) {
  222. $rows = 1;
  223. $body .= '<td width="50" rowspan="'.$rows.'">'.$v1.'</td>';
  224. $id[] = array
  225. (
  226. 'id' => $v['id'][$k1],
  227. 'attr_id' => $v['info_id'][$k1],
  228. );
  229. $key[] = $v['info_id'][$k1] . '-' . $v['id'][$k1];
  230. }
  231. $key = implode('_', $key);
  232. $s_price = $price = $num = '';
  233. if (isset($sku[$key])) {
  234. $s_price = $sku[$key]['s_price'];
  235. $price = $sku[$key]['price'];
  236. $num = $sku[$key]['num'];
  237. }
  238. $body .= '<td width="30"><input type="text" class="layui-input" name="s_price['.$k.']" value="'.$s_price.'"/></td>';
  239. $body .= '<td width="30"><input type="text" class="layui-input" name="price['.$k.']" value="'.$price.'"/></td>';
  240. $body .= '<td width="30"><input type="text" class="layui-input" name="num['.$k.']" value="'.$num.'"/><input type="hidden" name="key['.$k.']" value="'.$key.'"/><textarea style="display:none;" name="attr['.$k.']"/>'.json_encode($id).'</textarea></td>';
  241. $body .= '</tr>';
  242. }
  243. }
  244. $body .= '</tbody>';
  245. }
  246. $html = $head . $body;
  247. return $html;
  248. }
  249. }