Manage.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. /**
  126. * 显示订单信息
  127. *
  128. * @return mixed
  129. */
  130. public function order($id)
  131. {
  132. $info = Dever::db('goods/order')->one($id);
  133. if ($info) {
  134. $table['编号'] = '<font style="color:red">' . $info['id'] . '</font>';
  135. $table['订单号'] = '<font style="color:blue">' . $info['order_id'] . '</font>';
  136. $config = Dever::db('goods/info')->config;
  137. $table['平台'] = $config['config_platform'][$info['platform']];
  138. $table['形态'] = $config['config_shape'][$info['shape']];
  139. if ($info['type'] == 'collection') {
  140. $user = Dever::load('user/lib/info')->get($info['uid'], $info['type_id']);
  141. } else {
  142. $user = Dever::load('passport/api')->info($info['uid']);
  143. }
  144. $table['购买人'] = $user['username'] . '('.$user['mobile'].')';
  145. if ($info['parent_uid']) {
  146. if ($info['type'] == 'collection') {
  147. $user = Dever::load('user/lib/info')->get($info['parent_uid'], $info['type_id']);
  148. } else {
  149. $user = Dever::load('passport/api')->info($info['parent_uid']);
  150. }
  151. $table['邀请人'] = $user['username'] . '('.$user['mobile'].')';
  152. //$table['邀请人佣金'] = $info['parent_reward'] . '元';
  153. }
  154. $table['商品名'] = $info['name'];
  155. if ($info['sku_id']) {
  156. $sku = Dever::db('goods/info_sku')->one($info['sku_id']);
  157. }
  158. if ($info['mode'] > 0) {
  159. $mode = $config['config_mode'];
  160. $mode = $mode[$info['mode']];
  161. $table['配送方式'] = $mode;
  162. if ($info['area_id']) {
  163. $info['address'] = Dever::load('area/api')->string($info['area_id'], '') . $info['address'];
  164. }
  165. if ($info['address'] && $info['mode'] == 1) {
  166. $table['配送地址'] = $info['address'];
  167. $table['联系人'] = $info['username'];
  168. $table['联系电话'] = $info['mobile'];
  169. $table['运费'] = $info['freight_price'];
  170. }
  171. if ($info['store_id'] && $info['mode'] == 2) {
  172. $store = Dever::db('goods/store')->one($info['store_id']);
  173. $table['自提点'] = $store['name'];
  174. $table['自提码'] = $info['id'];
  175. }
  176. }
  177. $table['单价'] = $info['cash'] . '元';
  178. $table['数量'] = $info['num'];
  179. $table['总价'] = $info['price'] . '元';
  180. }
  181. return Dever::table($table);
  182. }
  183. private function attrInfo($info)
  184. {
  185. $table = array();
  186. $info = Info::init($info['top_category_id']);
  187. if ($info) {
  188. $info = $info->info($info, 'id');
  189. if ($info && isset($info['attr'])) {
  190. foreach ($info['attr'] as $k => $v) {
  191. $table[$v['name']] = $v['value_string'];
  192. }
  193. }
  194. }
  195. return Dever::table($table);
  196. }
  197. public function area($id, $name, $data)
  198. {
  199. # 不再执行syncone等后续操作
  200. Dever::config('base')->after = 1;
  201. $type = Dever::input('type');
  202. $area = Dever::param('area', $data);
  203. if ($area) {
  204. if (isset($area[2])) {
  205. $update['district_id'] = $area[2];
  206. }
  207. if (isset($area[1])) {
  208. $update['city_id'] = $area[1];
  209. }
  210. if (isset($area[0])) {
  211. $update['province_id'] = $area[0];
  212. }
  213. if (isset($update)) {
  214. $update['where_id'] = $id;
  215. Dever::db($type . '/info')->update($update);
  216. }
  217. }
  218. }
  219. public function skuConfig()
  220. {
  221. $data['action'] = Dever::url('goods/lib/manage.skuUp');
  222. $data['info_id'] = Dever::input('search_option_info_id');
  223. return $data;
  224. }
  225. public function skuUp_api()
  226. {
  227. $info_id = Dever::input('info_id');
  228. $attr = Dever::input('attr');
  229. $key = Dever::input('key');
  230. $price = Dever::input('price');
  231. $s_price = Dever::input('s_price');
  232. $num = Dever::input('num');
  233. if ($key) {
  234. foreach ($key as $k => $v) {
  235. if (isset($price[$k]) && $price[$k]) {
  236. $info = Dever::db('goods/info_sku')->one(array('key' => $v));
  237. $data['info_id'] = $info_id;
  238. $data['attr'] = $attr[$k];
  239. $data['key'] = $v;
  240. $data['price'] = $price[$k];
  241. $data['s_price'] = $s_price[$k];
  242. $data['num'] = $num[$k];
  243. if (!$info) {
  244. Dever::db('goods/info_sku')->insert($data);
  245. } else {
  246. $data['where_id'] = $info['id'];
  247. Dever::db('goods/info_sku')->update($data);
  248. }
  249. }
  250. }
  251. }
  252. Dever::out('yes');
  253. }
  254. public function skuInput()
  255. {
  256. $id = Dever::input('search_option_info_id');
  257. $sku = Dever::db('goods/info_sku')->getData(array('info_id' => $id));
  258. $info = Dever::db('goods/info')->one($id);
  259. $info = Info::init(-1)->info($info, 'list_reorder');
  260. $html = '请先选择属性';
  261. if ($info['sell_attr']) {
  262. $head = '<thead><tr>';
  263. $body = '<tbody>';
  264. $option = array();
  265. foreach ($info['sell_attr'] as $k => $v) {
  266. $head .= '<th>'.$v['name'].'</th>';
  267. if (isset($v['option_sku'])) {
  268. $option[$k] = $v['option_sku'];
  269. }
  270. }
  271. $head .= '<th>原价</th>';
  272. $head .= '<th>现价</th>';
  273. $head .= '<th>库存</th>';
  274. $head .= '</tr></thead>';
  275. if ($option) {
  276. $option = Dever::cartesian($option);
  277. foreach ($option as $k => $v) {
  278. $body .= '<tr data-row="' .($k+1). '">';
  279. $key = $id = array();
  280. foreach ($v['name'] as $k1 => $v1) {
  281. $rows = 1;
  282. $body .= '<td width="50" rowspan="'.$rows.'">'.$v1.'</td>';
  283. $id[] = array
  284. (
  285. 'id' => $v['id'][$k1],
  286. 'attr_id' => $v['info_id'][$k1],
  287. );
  288. $key[] = $v['info_id'][$k1] . '-' . $v['id'][$k1];
  289. }
  290. $key = implode('_', $key);
  291. $s_price = $price = $num = '';
  292. if (isset($sku[$key])) {
  293. $s_price = $sku[$key]['s_price'];
  294. $price = $sku[$key]['price'];
  295. $num = $sku[$key]['num'];
  296. }
  297. $body .= '<td width="30"><input type="text" class="layui-input" name="s_price['.$k.']" value="'.$s_price.'"/></td>';
  298. $body .= '<td width="30"><input type="text" class="layui-input" name="price['.$k.']" value="'.$price.'"/></td>';
  299. $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>';
  300. $body .= '</tr>';
  301. }
  302. }
  303. $body .= '</tbody>';
  304. $html = $head . $body;
  305. }
  306. return $html;
  307. }
  308. }