Manage.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. namespace Factory\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. # 导出订单
  7. public function out_api()
  8. {
  9. print_r(Dever::input());die;
  10. }
  11. /**
  12. * 更新信息
  13. *
  14. * @return mixed
  15. */
  16. public function infoUpdate($id, $name, $data)
  17. {
  18. $update = array();
  19. $area = Dever::param('area', $data);
  20. if ($area) {
  21. $temp = is_string($area) ? explode(',', $area) : $area;
  22. $update['province'] = $temp[0];
  23. $update['city'] = $temp[1];
  24. if (isset($temp[2])) {
  25. $update['county'] = $temp[2];
  26. }
  27. }
  28. $map = Dever::param('map', $data);
  29. if ($map) {
  30. $temp = is_string($map) ? explode(',', $map) : $map;
  31. if (isset($temp[1])) {
  32. $update['lng'] = $temp[1];
  33. $update['lat'] = $temp[2];
  34. }
  35. }
  36. $goods = Dever::param('goods', $data);
  37. if ($goods) {
  38. $goods = Dever::json_decode($goods);
  39. if ($goods) {
  40. foreach ($goods as $k1 => $v1) {
  41. if ($v1['value']) {
  42. foreach ($v1['value'] as $k => $v) {
  43. if ($v['state'] == 1) {
  44. $w = array();
  45. $w['goods_id'] = $v['id'];
  46. $w['factory_id'] = $id;
  47. $info = Dever::db('factory/goods')->one($w);
  48. $w['category_id'] = $v1['id'];
  49. if (!$info) {
  50. Dever::db('factory/goods')->insert($w);
  51. } else {
  52. $w['where_id'] = $info['id'];
  53. $w['state'] = 1;
  54. Dever::db('factory/goods')->update($w);
  55. }
  56. } else {
  57. unset($goods[$k1]['value'][$k]);
  58. }
  59. }
  60. }
  61. }
  62. $update['goods'] = Dever::json_encode($goods);
  63. }
  64. }
  65. if (isset($update) && $update) {
  66. $update['where_id'] = $id;
  67. Dever::db('factory/info')->update($update);
  68. }
  69. $truename = Dever::param('truename', $data);
  70. $mobile = Dever::param('mobile', $data);
  71. if ($mobile) {
  72. $member = Dever::db('factory/member')->one(array('factory_id' => $id, 'mobile' => $mobile));
  73. $update = array();
  74. $update['factory_id'] = $id;
  75. $update['name'] = $truename;
  76. $update['mobile'] = $mobile;
  77. if ($member) {
  78. $update['where_id'] = $member['id'];
  79. Dever::db('factory/member')->update($update);
  80. } else {
  81. Dever::db('factory/member')->insert($update);
  82. }
  83. }
  84. }
  85. /**
  86. * 更新商品信息 废弃
  87. *
  88. * @return mixed
  89. */
  90. public function goodsUpdate($id, $name, $data)
  91. {
  92. $update = array();
  93. $state = Dever::param('state', $data);
  94. if ($state) {
  95. Dever::config('base')->after = true;
  96. $info = Dever::db('factory/goods')->one($id);
  97. $factory_id = $info['factory_id'];
  98. $factory = Dever::db('factory/info')->one($factory_id);
  99. if ($factory && $factory['goods']) {
  100. $goods = Dever::json_decode($factory['goods']);
  101. if (isset($goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']])) {
  102. if ($state == 2) {
  103. unset($goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']]);
  104. }
  105. if (count($goods['level_' . $info['category_id']]['value']) <= 0) {
  106. unset($goods['level_' . $info['category_id']]);
  107. }
  108. } elseif ($state == 1) {
  109. $goods_info = Dever::db('goods/info')->one($info['goods_id']);
  110. $cate = Dever::load('category/api')->string($info['category_id']);
  111. $goods['level_' . $info['category_id']]['id'] = $info['category_id'];
  112. $goods['level_' . $info['category_id']]['name'] = $cate;
  113. $goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']] = array
  114. (
  115. 'id' => $info['goods_id'],
  116. 'name' => $goods_info['name'],
  117. 'state' => 1,
  118. );
  119. }
  120. $set['goods'] = Dever::json_encode($goods);
  121. $set['where_id'] = $factory_id;
  122. Dever::db('factory/info')->update($set);
  123. }
  124. }
  125. }
  126. # 根据分类获取商品
  127. public function getInfo_api()
  128. {
  129. $where['city'] = Dever::input('city');
  130. $data = Dever::db('factory/info')->select($where);
  131. return $data;
  132. }
  133. # 获取工厂
  134. public function search_api()
  135. {
  136. return Dever::search('factory/info');
  137. }
  138. # 获取工厂的商品列表
  139. public function goods_api()
  140. {
  141. $factory_id = Dever::input('factory_id', 1);
  142. return Dever::outDiy(Dever::load('factory/lib/goods')->getSkuList($factory_id));
  143. }
  144. # 获取收银台
  145. public function cashier_api()
  146. {
  147. $data = array();
  148. $data['factory_id'] = Dever::input('factory_id', 1);
  149. $data['host'] = Dever::url('lib/manage.cashier', 'factory');
  150. $data['url'] = Dever::url('lib/manage.goods?factory_id=' . $data['factory_id'], 'factory');
  151. $data['search'] = Dever::url('lib/manage.search?yes='.$data['factory_id'].'&json=1', 'factory');
  152. $data['search_store'] = Dever::url('lib/manage.search?json=1', 'store');
  153. $data['submit'] = Dever::url('lib/order.action_commit?json=1', 'factory');
  154. return Dever::render('cashier', $data);
  155. }
  156. }