Manage.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. $table = 'goods/info';
  29. $keyword = Dever::input('keyword');
  30. $yes = Dever::input('yes');
  31. $where = array();
  32. $cate = Dever::input('cate');
  33. if ($cate) {
  34. $where['cate_id'] = $cate;
  35. }
  36. $price_type = Dever::input('price_type');
  37. if ($price_type) {
  38. $where['price_type'] = $price_type;
  39. }
  40. if ($yes) {
  41. $yes = Dever::db($table)->search(array('ids' => $yes));
  42. }
  43. if (!$keyword) {
  44. $where['limit'] = '0,50';
  45. $data = Dever::db($table)->search($where);
  46. } else {
  47. $where['name'] = $keyword;
  48. $data = Dever::db($table)->search($where);
  49. }
  50. $result = array();
  51. if ($yes) {
  52. foreach ($yes as $k => $v) {
  53. if (isset($data[$k])) {
  54. unset($data[$k]);
  55. }
  56. $yes[$k]['selected'] = 'selected';
  57. }
  58. $data = $yes + $data;
  59. $data = array_merge($data, array());
  60. } else {
  61. $data = array_merge($data, array());
  62. }
  63. if (!$data) {
  64. Dever::alert('暂无数据');
  65. }
  66. return $data;
  67. }
  68. /**
  69. * 更新信息
  70. *
  71. * @return mixed
  72. */
  73. public function infoUpdate($id, $name, $data)
  74. {
  75. # 更新分类id
  76. $category = Dever::param('category', $data);
  77. if ($category) {
  78. if (is_array($category)) {
  79. $category_id = end($category);
  80. $top_category_id = $category[0];
  81. if (isset($category[1])) {
  82. $second_category_id = $category[1];
  83. } else {
  84. $second_category_id = $category[0];
  85. }
  86. } else {
  87. $category_id = $category;
  88. $top_category_id = $category;
  89. $second_category_id = $category;
  90. }
  91. $update['top_category_id'] = $top_category_id;
  92. $update['second_category_id'] = $second_category_id;
  93. $update['category_id'] = $category_id;
  94. }
  95. $pic = Dever::param('pic', $data);
  96. $pic_cover = Dever::param('pic_cover', $data);
  97. if ($pic && !$pic_cover) {
  98. if (is_string($pic)) {
  99. $pic = explode(',', $pic);
  100. }
  101. $update['pic_cover'] = $pic[0];
  102. }
  103. if (isset($update)) {
  104. $update['where_id'] = $id;
  105. Dever::db('goods/info')->update($update);
  106. }
  107. }
  108. /**
  109. * 更新需求属性信息
  110. *
  111. * @return mixed
  112. */
  113. public function attrUpdate($id, $name, $data)
  114. {
  115. print_r($data);die;
  116. foreach ($data as $k => $v) {
  117. }
  118. }
  119. public function column($cate, $im = ',')
  120. {
  121. if ($cate) {
  122. $cate = explode(',', $cate);
  123. $result = array();
  124. foreach ($cate as $k => $v) {
  125. $info = Dever::db('goods/column')->one($v);
  126. $result[$k] = $info['name'];
  127. }
  128. $result = implode($im, $result);
  129. return $result;
  130. }
  131. return '';
  132. }
  133. /**
  134. * 显示信息
  135. *
  136. * @return mixed
  137. */
  138. public function info($id)
  139. {
  140. $info = Dever::db('goods/info')->one($id);
  141. if ($info) {
  142. $table['编号'] = $info['id'];
  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. }
  160. $attr = $this->attrInfo($info);
  161. if ($attr) {
  162. $table['属性'] = $attr;
  163. }
  164. $table['价格'] = Dever::load('goods/lib/sku')->table($info['id'], false, false, false, false);
  165. if ($info['udate']) {
  166. $table['更新时间'] = date("Y-m-d H:i:s", $info['udate']);
  167. }
  168. if ($info['cdate']) {
  169. $table['发布时间'] = date("Y-m-d H:i:s", $info['cdate']);
  170. }
  171. }
  172. return Dever::table($table);
  173. }
  174. private function attrInfo($info)
  175. {
  176. $table = array();
  177. $class = Info::init($info['top_category_id']);
  178. if ($info) {
  179. $info = $class->info($info);
  180. if ($info && isset($info['attr'])) {
  181. foreach ($info['attr'] as $k => $v) {
  182. if ($v['value_string']) {
  183. $table[$v['name']] = $v['value_string'];
  184. }
  185. }
  186. }
  187. }
  188. return $table ? Dever::table($table) : false;
  189. }
  190. public function area($id, $name, $data)
  191. {
  192. # 不再执行syncone等后续操作
  193. Dever::config('base')->after = 1;
  194. $type = Dever::input('type');
  195. $area = Dever::param('area', $data);
  196. if ($area) {
  197. if (isset($area[2])) {
  198. $update['district_id'] = $area[2];
  199. }
  200. if (isset($area[1])) {
  201. $update['city_id'] = $area[1];
  202. }
  203. if (isset($area[0])) {
  204. $update['province_id'] = $area[0];
  205. }
  206. if (isset($update)) {
  207. $update['where_id'] = $id;
  208. Dever::db($type . '/info')->update($update);
  209. }
  210. }
  211. }
  212. /**
  213. * 显示用户信息
  214. *
  215. * @return mixed
  216. */
  217. public function showUserInfo($id)
  218. {
  219. $info = Dever::db('goods/card_code')->find($id);
  220. $table = array();
  221. if ($info && $info['status'] > 1 && $info['uid'] && $info['uid'] > 0) {
  222. $user = Dever::load('passport/user-one', $info['uid']);
  223. $shop = Dever::load('shop/info-one', $info['shop_id']);
  224. if ($user) {
  225. $table['领取门店'] = $shop['name'] . '('.$shop['mobile'].')';
  226. $table['领取人'] = $user['username'] . '('.$info['uid'].')';
  227. $table['手机号'] = $user['mobile'];
  228. $table['兑换时间'] = date('Y-m-d H:i:s', $info['ddate']);
  229. }
  230. }
  231. return Dever::table($table);
  232. }
  233. /**
  234. * 创建兑换码
  235. *
  236. * @return mixed
  237. */
  238. public function createCard($id, $name, $param)
  239. {
  240. $num = Dever::param('num', $param);
  241. $card_id = Dever::param('card_id', $param);
  242. $info = Dever::db('goods/card')->find($card_id);
  243. if ($info && $num > 0) {
  244. for ($i = 0; $i< $num;$i++) {
  245. $this->createCode($info);
  246. }
  247. }
  248. }
  249. private function createCode($info)
  250. {
  251. # 生成卡号和密码
  252. $card = $info['card_prefix'] . Dever::rand($info['card_len'], $info['card_type'] - 1);
  253. $pwd = $info['pwd_prefix'] . Dever::rand($info['pwd_len'], $info['pwd_type'] - 1);
  254. $where['card'] = $card;
  255. $where['pwd'] = $pwd;
  256. $state = Dever::db('goods/card_code')->find($where);
  257. if (!$state) {
  258. $where['card_id'] = $info['id'];
  259. if ($info['type'] == 1) {
  260. $info['day'] = 3650;
  261. }
  262. $where['edate'] = time() + ($info['day']*86400);
  263. Dever::db('goods/card_code')->insert($where);
  264. } else {
  265. $this->createCode($info);
  266. }
  267. }
  268. /**
  269. * 作废
  270. *
  271. * @return mixed
  272. */
  273. public function drop_api($id)
  274. {
  275. $update['where_id'] = $id;
  276. $update['type'] = 4;
  277. Dever::db('goods/card_code')->update($update);
  278. return 'ok';
  279. }
  280. public function recovery_api($id)
  281. {
  282. $update['where_id'] = $id;
  283. $update['type'] = 1;
  284. Dever::db('goods/card_code')->update($update);
  285. return 'ok';
  286. }
  287. public function editor_api()
  288. {
  289. $data['name'] = '商品';
  290. $where = array();
  291. $name = Dever::input('search_name');
  292. $cate = Dever::input('search_cate');
  293. if ($name) {
  294. $where['name'] = $name;
  295. }
  296. if ($cate > 0) {
  297. $where['column_id'] = $cate;
  298. }
  299. $data['file'] = Dever::db('goods/info')->getPageAll($where);
  300. $data['cate'] = Dever::db('goods/column')->select();
  301. if ($data['file']) {
  302. foreach ($data['file'] as $k => $v) {
  303. $data['file'][$k]['source_name'] = $v['name'];
  304. $data['file'][$k]['file'] = $v['cover'];
  305. $data['file'][$k]['pic'] = $v['cover'];
  306. }
  307. }
  308. return $data;
  309. }
  310. }