Manage.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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['name'];
  141. $table['编号'] = $info['id'];
  142. $table['税点'] = $info['tax'];
  143. $table['栏目'] = $this->column($info['column_id']);
  144. //$table['标题'] = $info['name'];
  145. $table['分类'] = Dever::load("category/api.string", $info['category']);
  146. if ($info['cover']) {
  147. $table['商品图'] = '<img src="'.$info['cover'].'" width="150" />';
  148. }
  149. if ($info['price_type'] == 3) {
  150. # 获取套餐的商品
  151. $goods = Dever::array_decode($info['goods']);
  152. foreach ($goods as $k => $v) {
  153. $goods_info = Dever::db('goods/info')->one($v['goods_id']);
  154. if ($goods_info) {
  155. $table['套餐商品'][] = $v['num'] . '个' . $goods_info['name'];
  156. }
  157. }
  158. $table['套餐商品'] = implode(',', $table['套餐商品']);
  159. } elseif ($info['price_type'] == 4) {
  160. # 获取套餐的商品
  161. $goods = Dever::array_decode($info['goods']);
  162. foreach ($goods as $k => $v) {
  163. $goods_info = Dever::db('goods/info')->one($v['goods_id']);
  164. if ($goods_info) {
  165. $table['组合商品'][] = $v['num'] . '个' . $goods_info['name'];
  166. }
  167. }
  168. $table['组合商品'] = implode(',', $table['组合商品']);
  169. }
  170. $attr = $this->attrInfo($info);
  171. if ($attr) {
  172. $table['属性'] = $attr;
  173. }
  174. $table['价格'] = Dever::load('goods/lib/sku')->table($info['id'], false, false, false, false);
  175. if ($info['udate']) {
  176. $table['更新时间'] = date("Y-m-d H:i:s", $info['udate']);
  177. }
  178. if ($info['cdate']) {
  179. $table['发布时间'] = date("Y-m-d H:i:s", $info['cdate']);
  180. }
  181. }
  182. return Dever::table($table);
  183. }
  184. private function attrInfo($info)
  185. {
  186. $table = array();
  187. $class = Info::init($info['top_category_id']);
  188. if ($info) {
  189. $info = $class->info($info);
  190. if ($info && isset($info['attr'])) {
  191. foreach ($info['attr'] as $k => $v) {
  192. if ($v['value_string']) {
  193. $table[$v['name']] = $v['value_string'];
  194. }
  195. }
  196. }
  197. }
  198. return $table ? Dever::table($table) : false;
  199. }
  200. public function area($id, $name, $data)
  201. {
  202. # 不再执行syncone等后续操作
  203. Dever::config('base')->after = 1;
  204. $type = Dever::input('type');
  205. $area = Dever::param('area', $data);
  206. if ($area) {
  207. if (isset($area[2])) {
  208. $update['district_id'] = $area[2];
  209. }
  210. if (isset($area[1])) {
  211. $update['city_id'] = $area[1];
  212. }
  213. if (isset($area[0])) {
  214. $update['province_id'] = $area[0];
  215. }
  216. if (isset($update)) {
  217. $update['where_id'] = $id;
  218. Dever::db($type . '/info')->update($update);
  219. }
  220. }
  221. }
  222. /**
  223. * 显示用户信息
  224. *
  225. * @return mixed
  226. */
  227. public function showUserInfo($id)
  228. {
  229. $info = Dever::db('goods/card_code')->find($id);
  230. $table = array();
  231. if ($info && $info['status'] > 1 && $info['uid'] && $info['uid'] > 0) {
  232. $user = Dever::load('passport/user-one', $info['uid']);
  233. $shop = Dever::load('shop/info-one', $info['shop_id']);
  234. if ($user) {
  235. $table['领取门店'] = $shop['name'] . '('.$shop['mobile'].')';
  236. $table['领取人'] = $user['username'] . '('.$info['uid'].')';
  237. $table['手机号'] = $user['mobile'];
  238. $table['兑换时间'] = date('Y-m-d H:i:s', $info['ddate']);
  239. }
  240. }
  241. return Dever::table($table);
  242. }
  243. /**
  244. * 创建兑换码
  245. *
  246. * @return mixed
  247. */
  248. public function createCard($id, $name, $param)
  249. {
  250. $num = Dever::param('num', $param);
  251. $card_id = Dever::param('card_id', $param);
  252. $info = Dever::db('goods/card')->find($card_id);
  253. if ($info && $num > 0) {
  254. for ($i = 0; $i< $num;$i++) {
  255. $this->createCode($info);
  256. }
  257. }
  258. }
  259. private function createCode($info)
  260. {
  261. # 生成卡号和密码
  262. $card = $info['card_prefix'] . Dever::rand($info['card_len'], $info['card_type'] - 1);
  263. $pwd = $info['pwd_prefix'] . Dever::rand($info['pwd_len'], $info['pwd_type'] - 1);
  264. $where['card'] = $card;
  265. $where['pwd'] = $pwd;
  266. $state = Dever::db('goods/card_code')->find($where);
  267. if (!$state) {
  268. $where['card_id'] = $info['id'];
  269. if ($info['type'] == 1) {
  270. $info['day'] = 3650;
  271. }
  272. $where['edate'] = time() + ($info['day']*86400);
  273. Dever::db('goods/card_code')->insert($where);
  274. } else {
  275. $this->createCode($info);
  276. }
  277. }
  278. /**
  279. * 作废
  280. *
  281. * @return mixed
  282. */
  283. public function drop_api($id)
  284. {
  285. $update['where_id'] = $id;
  286. $update['type'] = 4;
  287. Dever::db('goods/card_code')->update($update);
  288. return 'ok';
  289. }
  290. public function recovery_api($id)
  291. {
  292. $update['where_id'] = $id;
  293. $update['type'] = 1;
  294. Dever::db('goods/card_code')->update($update);
  295. return 'ok';
  296. }
  297. public function editor_api()
  298. {
  299. $data['name'] = '商品';
  300. $where = array();
  301. $name = Dever::input('search_name');
  302. $cate = Dever::input('search_cate');
  303. if ($name) {
  304. $where['name'] = $name;
  305. }
  306. if ($cate > 0) {
  307. $where['column_id'] = $cate;
  308. }
  309. $data['file'] = Dever::db('goods/info')->getPageAll($where);
  310. $data['cate'] = Dever::db('goods/column')->select();
  311. if ($data['file']) {
  312. foreach ($data['file'] as $k => $v) {
  313. $data['file'][$k]['source_name'] = $v['name'];
  314. $data['file'][$k]['file'] = $v['cover'];
  315. $data['file'][$k]['pic'] = $v['cover'];
  316. }
  317. }
  318. return $data;
  319. }
  320. }