Manage.php 11 KB

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