Manage.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <?php
  2. namespace Shop\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. # 获取用户信息
  7. public function user($id)
  8. {
  9. $info = Dever::db('shop/sell_order')->one($id);
  10. if ($info['uid'] && $info['uid'] > 0) {
  11. $user = Dever::db('passport/user')->one($info['uid']);
  12. $result = $user['username'];
  13. if ($info['mobile']) {
  14. $result .= '('.$info['mobile'].')';
  15. }
  16. } else {
  17. $result = $info['mobile'];
  18. }
  19. return $result;
  20. }
  21. # 获取订单信息
  22. public function sell_order($id)
  23. {
  24. $table = array();
  25. $info = Dever::db('shop/sell_order')->one($id);
  26. $goods = Dever::db('shop/sell_order_goods')->select(array('order_id' => $info['id']));
  27. foreach ($goods as $k => $v) {
  28. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
  29. //print_r($goods_info);die;
  30. $table[$goods_info['name']] = $v['price'];
  31. }
  32. return Dever::table($table);
  33. }
  34. /**
  35. * 更新信息
  36. *
  37. * @return mixed
  38. */
  39. public function upInfo($id, $name, $data)
  40. {
  41. Dever::config('base')->hook = true;
  42. }
  43. /**
  44. * 更新信息
  45. *
  46. * @return mixed
  47. */
  48. public function printInsert($id, $name, $data)
  49. {
  50. Dever::config('base')->hook = true;
  51. $name = Dever::param('name', $data);
  52. $number = Dever::param('number', $data);
  53. $phonenum = Dever::param('phonenum', $data);
  54. $key = Dever::param('key', $data);
  55. if ($number && $key) {
  56. $data = array();
  57. $data['name'] = $name;
  58. $data['number'] = $number;
  59. $data['phonenum'] = $phonenum;
  60. $data['key'] = $key;
  61. $result = Dever::load('mshop/lib/feieyun')->add(array($data));
  62. if (isset($result['no'][0]) && $result['no'][0] && strstr($result['no'][0], '编号不合法')) {
  63. Dever::db('shop/print')->update(array('where_id' => $id, 'status' => 10));
  64. } else {
  65. Dever::db('shop/print')->update(array('where_id' => $id, 'status' => 1));
  66. }
  67. }
  68. }
  69. /**
  70. * 更新信息
  71. *
  72. * @return mixed
  73. */
  74. public function printUpdate($id, $name, $data)
  75. {
  76. Dever::config('base')->hook = true;
  77. $info = Dever::db('shop/print')->one($id);
  78. $name = Dever::param('name', $data);
  79. $phonenum = Dever::param('phonenum', $data);
  80. if ($info && $name) {
  81. if ($info['status'] == 10) {
  82. $this->printInsert($id, $name, $info);
  83. } else {
  84. Dever::load('mshop/lib/feieyun')->edit($info['number'], $name, $phonenum);
  85. }
  86. }
  87. }
  88. /**
  89. * 打印机状态
  90. *
  91. * @return mixed
  92. */
  93. public function printStatus($status, $sn)
  94. {
  95. return $status >= 10 ? '绑定失败' : Dever::load('mshop/lib/feieyun')->status($sn);
  96. }
  97. /**
  98. * 更新信息
  99. *
  100. * @return mixed
  101. */
  102. public function couponUpdate($id, $name, $data)
  103. {
  104. Dever::config('base')->hook = true;
  105. $update = array();
  106. $coupon = Dever::param('coupon', $data);
  107. if ($coupon) {
  108. $temp = is_string($coupon) ? explode(',', $coupon) : $coupon;
  109. $update['method'] = $temp[0];
  110. $update['coupon_id'] = $temp[1];
  111. }
  112. $shop_id = Dever::param('shop_id', $data);
  113. if ($shop_id) {
  114. $shop = Dever::db('shop/info')->find($shop_id);
  115. $update['city'] = $shop['city'];
  116. }
  117. if (isset($update) && $update) {
  118. $update['where_id'] = $id;
  119. Dever::db('shop/coupon')->update($update);
  120. }
  121. }
  122. /**
  123. * 更新信息
  124. *
  125. * @return mixed
  126. */
  127. public function infoUpdate($id, $name, $data)
  128. {
  129. $update = array();
  130. $area = Dever::param('area', $data);
  131. if ($area) {
  132. $temp = is_string($area) ? explode(',', $area) : $area;
  133. $update['province'] = $temp[0];
  134. $update['city'] = $temp[1];
  135. if (isset($temp[2])) {
  136. $update['county'] = $temp[2];
  137. }
  138. if (isset($temp[3])) {
  139. $update['town'] = $temp[3];
  140. }
  141. }
  142. $map = Dever::param('map', $data);
  143. if ($map) {
  144. $temp = is_string($map) ? explode(',', $map) : $map;
  145. if (isset($temp[1])) {
  146. $update['lng'] = $temp[1];
  147. $update['lat'] = $temp[2];
  148. $address = Dever::param('address', $data);
  149. $update['coord_address'] = Dever::load('shop/lib/info')->address($temp[1], $temp[2]);
  150. if (!$address && $update['coord_address']) {
  151. $update['address'] = $update['coord_address'];
  152. }
  153. }
  154. }
  155. $act = Dever::param('act', $data);
  156. if ($act) {
  157. foreach ($act as $k => $v) {
  158. $w = array();
  159. $w['shop_id'] = $id;
  160. $w['act_id'] = $k;
  161. foreach ($v as $k1 => $v1) {
  162. $w['shop_coupon_id'] = $v1;
  163. $info = Dever::db('shop/coupon_act')->find($w);
  164. if (!$info) {
  165. Dever::db('shop/coupon_act')->insert($w);
  166. }
  167. }
  168. }
  169. }
  170. Dever::upLinkage($update, $id, $data, 'goods', 'shop/goods', 'shop_id', 'goods_id', 'category_id');
  171. Dever::upLinkage($update, $id, $data, 'factory', 'shop/factory', 'shop_id', 'factory_id', 'city');
  172. Dever::upLinkage($update, $id, $data, 'store', 'shop/store', 'shop_id', 'store_id', 'city');
  173. if (isset($update) && $update) {
  174. $update['where_id'] = $id;
  175. Dever::db('shop/info')->update($update);
  176. }
  177. $truename = Dever::param('truename', $data);
  178. $mobile = Dever::param('mobile', $data);
  179. if ($mobile) {
  180. $member = Dever::db('shop/member')->one(array('shop_id' => $id, 'mobile' => $mobile));
  181. $update = array();
  182. $update['shop_id'] = $id;
  183. $update['name'] = $truename;
  184. $update['mobile'] = $mobile;
  185. if ($member) {
  186. $update['where_id'] = $member['id'];
  187. Dever::db('shop/member')->update($update);
  188. } else {
  189. Dever::db('shop/member')->insert($update);
  190. }
  191. }
  192. }
  193. private function updateParam()
  194. {
  195. }
  196. /**
  197. * 更新商品信息
  198. *
  199. * @return mixed
  200. */
  201. public function goodsUpdate($id, $name, $data)
  202. {
  203. $update = array();
  204. $state = Dever::param('state', $data);
  205. if ($state) {
  206. Dever::config('base')->after = true;
  207. $info = Dever::db('shop/goods')->one($id);
  208. $shop_id = $info['shop_id'];
  209. $shop = Dever::db('shop/info')->one($shop_id);
  210. if ($shop && $shop['goods']) {
  211. $goods = Dever::json_decode($shop['goods']);
  212. if (isset($goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']])) {
  213. if ($state == 2) {
  214. unset($goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']]);
  215. }
  216. if (count($goods['level_' . $info['category_id']]['value']) <= 0) {
  217. unset($goods['level_' . $info['category_id']]);
  218. }
  219. } elseif ($state == 1) {
  220. $goods_info = Dever::db('goods/info')->one($info['goods_id']);
  221. $cate = Dever::load('category/api')->string($info['category_id']);
  222. $goods['level_' . $info['category_id']]['id'] = $info['category_id'];
  223. $goods['level_' . $info['category_id']]['name'] = $cate;
  224. $goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']] = array
  225. (
  226. 'id' => $info['goods_id'],
  227. 'name' => $goods_info['name'],
  228. 'state' => 1,
  229. );
  230. }
  231. $set['goods'] = Dever::json_encode($goods);
  232. $set['where_id'] = $shop_id;
  233. Dever::db('shop/info')->update($set);
  234. }
  235. }
  236. }
  237. /**
  238. * 更新库存信息
  239. *
  240. * @return mixed
  241. */
  242. public function skuUpdate($id, $name, $data)
  243. {
  244. $update = array();
  245. $add_num = Dever::param('add_num', $data);
  246. if ($add_num) {
  247. $state = Dever::db('shop/goods_sku')->updateTotal(array('where_id' => $id, 'total_num' => $add_num));
  248. if ($state) {
  249. $state = Dever::db('shop/goods_sku')->update(array('where_id' => $id, 'add_num' => 0));
  250. $info = Dever::db('shop/goods_sku')->one($id);
  251. $goods = Dever::db('shop/goods')->one(array('goods_id' => $info['goods_id'], 'shop_id' => $info['shop_id']));
  252. if ($goods) {
  253. Dever::db('shop/goods')->update(array('where_id' => $goods['id'], 'total_num' => $info['total_num'], 'add_num' => 0));
  254. }
  255. if ($add_num < 0) {
  256. # 记录出库日志
  257. } else {
  258. # 记录入库日志
  259. }
  260. }
  261. }
  262. }
  263. # 获取供货商信息
  264. public function buyInfo($type = '', $type_id = '')
  265. {
  266. if ($type == 1) {
  267. $type_info = Dever::db('shop/info')->find($type_id);
  268. return $type_info['name'] . '('.$type_info['mobile'].')';
  269. } elseif ($type == 2) {
  270. $type_info = Dever::db('store/info')->find($type_id);
  271. return $type_info['name'] . '('.$type_info['mobile'].')';
  272. } elseif ($type == 3) {
  273. $type_info = Dever::db('factory/info')->find($type_id);
  274. return $type_info['name'] . '('.$type_info['mobile'].')';
  275. } else {
  276. return '无';
  277. }
  278. }
  279. /**
  280. * 更新信息
  281. *
  282. * @return mixed
  283. */
  284. public function buyOrderPs($id, $name, $data)
  285. {
  286. $order_id = Dever::param('order_id', $data);
  287. if ($order_id) {
  288. $update['where_id'] = $order_id;
  289. $update['set_status'] = 4;
  290. Dever::db('shop/buy_order')->update($update);
  291. }
  292. }
  293. # 获取门店
  294. public function search_api()
  295. {
  296. return Dever::search('shop/info');
  297. }
  298. }