Manage.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <?php
  2. namespace Goods\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function getByName_api()
  7. {
  8. $data = Dever::db('goods/info')->getAllByName(array
  9. (
  10. 'name' => Dever::input('term'))
  11. );
  12. if ($data) {
  13. return $data;
  14. }
  15. return array
  16. (
  17. 0 => array('id' => -1, 'value' => '没有找到您搜索的数据', 'label' => '没有找到您搜索的数据'),
  18. );
  19. }
  20. public function getByCate()
  21. {
  22. $cate = Dever::input('cate');
  23. $data = Dever::db('goods/info')->getAllByCate(array('top_category_id' => $cate));
  24. return Dever::load('manage/database')->getAjax($data);
  25. }
  26. public function search_api()
  27. {
  28. $where = array();
  29. $cate = Dever::input('cate');
  30. if ($cate) {
  31. $where['cate_id'] = $cate;
  32. }
  33. $price_type = Dever::input('price_type');
  34. if ($price_type) {
  35. $where['price_type'] = $price_type;
  36. }
  37. return Dever::search('goods/info', $where);
  38. }
  39. public function search_sku_api()
  40. {
  41. $where = array();
  42. $info_id = Dever::input('info_id');
  43. if ($info_id) {
  44. $where['info_id'] = $info_id;
  45. }
  46. $data = Dever::search('goods/info_sku', $where);
  47. if ($data) {
  48. foreach ($data as $k => $v) {
  49. $v['attr'] = Dever::json_decode($v['attr']);
  50. if ($v['attr']) {
  51. $v['attr'] = Dever::load('attr/api')->getInfoByJson($v['attr']);
  52. $v['name'] = $v['attr']['string'];
  53. }
  54. }
  55. }
  56. return $data;
  57. }
  58. /**
  59. * 更新信息
  60. *
  61. * @return mixed
  62. */
  63. public function infoUpdate($id, $name, $data)
  64. {
  65. $status = Dever::param('status', $data);
  66. if ($status > 0) {
  67. Dever::db('shop/goods')->updates(array('option_goods_id' => $id, 'set_status' => $status));
  68. Dever::db('store/goods')->updates(array('option_goods_id' => $id, 'set_status' => $status));
  69. Dever::db('factory/goods')->updates(array('option_goods_id' => $id, 'set_status' => $status));
  70. Dever::db('shop/goods_sku')->updates(array('option_goods_id' => $id, 'set_status' => $status));
  71. Dever::db('store/goods_sku')->updates(array('option_goods_id' => $id, 'set_status' => $status));
  72. }
  73. # 更新分类id
  74. $category = Dever::param('category', $data);
  75. if ($category) {
  76. if (is_array($category)) {
  77. $category_id = end($category);
  78. $top_category_id = $category[0];
  79. if (isset($category[1])) {
  80. $second_category_id = $category[1];
  81. } else {
  82. $second_category_id = $category[0];
  83. }
  84. } else {
  85. $category_id = $category;
  86. $top_category_id = $category;
  87. $second_category_id = $category;
  88. }
  89. $update['top_category_id'] = $top_category_id;
  90. $update['second_category_id'] = $second_category_id;
  91. $update['category_id'] = $category_id;
  92. }
  93. $pic = Dever::param('pic', $data);
  94. $pic_cover = Dever::param('pic_cover', $data);
  95. if ($pic && !$pic_cover) {
  96. if (is_string($pic)) {
  97. $pic = explode(',', $pic);
  98. }
  99. $update['pic_cover'] = $pic[0];
  100. }
  101. if (isset($update)) {
  102. $update['where_id'] = $id;
  103. Dever::db('goods/info')->update($update);
  104. }
  105. }
  106. /**
  107. * 更新需求属性信息
  108. *
  109. * @return mixed
  110. */
  111. public function attrUpdate($id, $name, $data)
  112. {
  113. print_r($data);die;
  114. foreach ($data as $k => $v) {
  115. }
  116. }
  117. public function column($cate, $im = ',')
  118. {
  119. if ($cate) {
  120. $cate = explode(',', $cate);
  121. $result = array();
  122. foreach ($cate as $k => $v) {
  123. $info = Dever::db('goods/column')->one($v);
  124. $result[$k] = $info['name'];
  125. }
  126. $result = implode($im, $result);
  127. return $result;
  128. }
  129. return '';
  130. }
  131. /**
  132. * 显示信息
  133. *
  134. * @return mixed
  135. */
  136. public function info($id)
  137. {
  138. $info = Dever::db('goods/info')->one($id);
  139. if ($info) {
  140. $table['编号'] = $info['id'];
  141. $table['栏目'] = $this->column($info['column_id']);
  142. //$table['标题'] = $info['name'];
  143. $table['分类'] = Dever::load("category/api.string", $info['category']);
  144. if ($info['cover']) {
  145. $table['商品图'] = '<img src="'.$info['cover'].'" width="150" />';
  146. }
  147. if ($info['price_type'] == 3) {
  148. # 获取套餐的商品
  149. $goods = Dever::array_decode($info['goods']);
  150. foreach ($goods as $k => $v) {
  151. $goods_info = Dever::db('goods/info')->one($v['goods_id']);
  152. if ($goods_info) {
  153. $table['套餐商品'][] = $v['num'] . '个' . $goods_info['name'];
  154. }
  155. }
  156. $table['套餐商品'] = implode(',', $table['套餐商品']);
  157. } elseif ($info['price_type'] == 4) {
  158. # 获取套餐的商品
  159. $goods = Dever::array_decode($info['goods']);
  160. foreach ($goods as $k => $v) {
  161. $goods_info = Dever::db('goods/info')->one($v['goods_id']);
  162. if ($goods_info) {
  163. $table['组合商品'][] = $v['num'] . '个' . $goods_info['name'];
  164. }
  165. }
  166. $table['组合商品'] = implode(',', $table['组合商品']);
  167. }
  168. $attr = $this->attrInfo($info);
  169. if ($attr) {
  170. $table['属性'] = $attr;
  171. }
  172. $table['价格'] = Dever::load('goods/lib/sku')->table($info['id'], false, false, false, false);
  173. if ($info['udate']) {
  174. $table['更新时间'] = date("Y-m-d H:i:s", $info['udate']);
  175. }
  176. if ($info['cdate']) {
  177. $table['发布时间'] = date("Y-m-d H:i:s", $info['cdate']);
  178. }
  179. }
  180. return Dever::table($table);
  181. }
  182. private function attrInfo($info)
  183. {
  184. $table = array();
  185. $class = Info::init($info['top_category_id']);
  186. if ($info) {
  187. $info = $class->info($info);
  188. if ($info && isset($info['attr'])) {
  189. foreach ($info['attr'] as $k => $v) {
  190. if ($v['value_string']) {
  191. $table[$v['name']] = $v['value_string'];
  192. }
  193. }
  194. }
  195. }
  196. return $table ? Dever::table($table) : false;
  197. }
  198. public function area($id, $name, $data)
  199. {
  200. # 不再执行syncone等后续操作
  201. Dever::config('base')->after = 1;
  202. $type = Dever::input('type');
  203. $area = Dever::param('area', $data);
  204. if ($area) {
  205. if (isset($area[2])) {
  206. $update['district_id'] = $area[2];
  207. }
  208. if (isset($area[1])) {
  209. $update['city_id'] = $area[1];
  210. }
  211. if (isset($area[0])) {
  212. $update['province_id'] = $area[0];
  213. }
  214. if (isset($update)) {
  215. $update['where_id'] = $id;
  216. Dever::db($type . '/info')->update($update);
  217. }
  218. }
  219. }
  220. /**
  221. * 显示用户信息
  222. *
  223. * @return mixed
  224. */
  225. public function showUserInfo($id)
  226. {
  227. $info = Dever::db('goods/card_code')->find($id);
  228. $table = array();
  229. if ($info && $info['status'] > 1 && $info['uid'] && $info['uid'] > 0) {
  230. $user = Dever::load('passport/user-one', $info['uid']);
  231. $shop = Dever::load('shop/info-one', $info['shop_id']);
  232. if ($user) {
  233. $table['领取门店'] = $shop['name'] . '('.$shop['mobile'].')';
  234. $table['领取人'] = $user['username'] . '('.$info['uid'].')';
  235. $table['手机号'] = $user['mobile'];
  236. $table['兑换时间'] = date('Y-m-d H:i:s', $info['ddate']);
  237. }
  238. }
  239. return Dever::table($table);
  240. }
  241. /**
  242. * 创建兑换码
  243. *
  244. * @return mixed
  245. */
  246. public function createCard($id, $name, $param)
  247. {
  248. $num = Dever::param('num', $param);
  249. $card_id = Dever::param('card_id', $param);
  250. $info = Dever::db('goods/card')->find($card_id);
  251. if ($info && $num > 0) {
  252. for ($i = 0; $i< $num;$i++) {
  253. $this->createCode($info);
  254. }
  255. }
  256. }
  257. private function createCode($info)
  258. {
  259. # 生成卡号和密码
  260. $card = $info['card_prefix'] . Dever::rand($info['card_len'], $info['card_type'] - 1);
  261. $pwd = $info['pwd_prefix'] . Dever::rand($info['pwd_len'], $info['pwd_type'] - 1);
  262. $where['card'] = $card;
  263. $where['pwd'] = $pwd;
  264. $state = Dever::db('goods/card_code')->find($where);
  265. if (!$state) {
  266. $where['card_id'] = $info['id'];
  267. if ($info['type'] == 1) {
  268. $info['day'] = 3650;
  269. }
  270. $where['edate'] = time() + ($info['day']*86400);
  271. Dever::db('goods/card_code')->insert($where);
  272. } else {
  273. $this->createCode($info);
  274. }
  275. }
  276. /**
  277. * 作废
  278. *
  279. * @return mixed
  280. */
  281. public function drop_api($id)
  282. {
  283. $update['where_id'] = $id;
  284. $update['type'] = 4;
  285. Dever::db('goods/card_code')->update($update);
  286. return 'ok';
  287. }
  288. public function recovery_api($id)
  289. {
  290. $update['where_id'] = $id;
  291. $update['type'] = 1;
  292. Dever::db('goods/card_code')->update($update);
  293. return 'ok';
  294. }
  295. public function editor_api()
  296. {
  297. $data['name'] = '商品';
  298. $where = array();
  299. $name = Dever::input('search_name');
  300. $cate = Dever::input('search_cate');
  301. if ($name) {
  302. $where['name'] = $name;
  303. }
  304. if ($cate > 0) {
  305. $where['column_id'] = $cate;
  306. }
  307. $data['file'] = Dever::db('goods/info')->getPageAll($where);
  308. $data['cate'] = Dever::db('goods/column')->select();
  309. if ($data['file']) {
  310. foreach ($data['file'] as $k => $v) {
  311. $data['file'][$k]['source_name'] = $v['name'];
  312. $data['file'][$k]['file'] = $v['cover'];
  313. $data['file'][$k]['pic'] = $v['cover'];
  314. }
  315. }
  316. return $data;
  317. }
  318. }