Unmarket.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 团购联盟
  7. */
  8. namespace app\allwin\controller\Manage;
  9. use app\allwin\controller\Common;
  10. use app\allwin\model\AllwinUnmarket;
  11. use app\allwin\model\AllwinUnmarketOrder;
  12. use app\allwin\model\AllwinUnmarketStore;
  13. use app\allwin\model\AllwinUnmarketVerif;
  14. use app\allwin\model\AllwinUnmarketBooking;
  15. use app\allwin\model\AllwinStore;
  16. class Unmarket extends Common{
  17. public function initialize() {
  18. parent::initialize();
  19. $this->assign('pathMaps',[['name'=>'团购联盟','url' => url('manage.unmarket/index')]]);
  20. }
  21. /**
  22. * 列表
  23. */
  24. public function index(){
  25. $condition = [];
  26. $condition['member_miniapp_id'] = $this->member_miniapp_id;
  27. $view['lists'] = AllwinUnmarket::where($condition)->order('id desc')->paginate(20);
  28. return view()->assign($view);
  29. }
  30. /**
  31. * 添加
  32. */
  33. public function add(){
  34. if(request()->isAjax()){
  35. $data = [
  36. 'uid' => input('post.uid/d'),
  37. 'member_miniapp_id' => $this->member_miniapp_id,
  38. 'telphone' => input('post.telphone/s'),
  39. 'mycode' => input('post.mycode/s'),
  40. 'tips' => input('post.tips/s'),
  41. 'title' => input('post.title/s'),
  42. 'bonus_types' => input('post.bonus_types/d'),
  43. 'bonus_user_types' => input('post.bonus_user_types/d'),
  44. 'share_ratio_user' => input('post.share_ratio_user/d'),
  45. 'share_ratio' => input('post.share_ratio/f'),
  46. 'price' => input('post.price/f'),
  47. 'name' => input('post.name/s'),
  48. 'address' => input('post.address/s'),
  49. 'tel' => input('post.address/s'),
  50. 'share_img' => input('post.share_img/s'),
  51. 'share_title' => input('post.share_title/s'),
  52. 'share_text' => input('post.share_text/s'),
  53. 'music' => input('post.music/s'),
  54. 'note' => input('post.note/s'),
  55. 'img' => input('post.img/s'),
  56. 'imgs' => input('post.imgs/a'),
  57. 'start_time' => input('post.start_time/s'),
  58. 'end_time' => input('post.end_time/s'),
  59. ];
  60. $validate = $this->validate($data,'Unmarket.add');
  61. if(true !== $validate){
  62. return json(['code'=>0,'msg'=>$validate]);
  63. }
  64. $result = AllwinUnmarket::edit($data);
  65. if($result){
  66. return json(['code'=>200,'url'=>url('manage.unmarket/index'),'msg'=>'操作成功']);
  67. }else{
  68. return json(['code'=>0,'msg'=>'操作失败']);
  69. }
  70. }else{
  71. return view();
  72. }
  73. }
  74. //编辑
  75. public function edit(){
  76. if(request()->isAjax()){
  77. $data = [
  78. 'id' => input('post.id/d'),
  79. 'uid' => input('post.uid/d'),
  80. 'member_miniapp_id' => $this->member_miniapp_id,
  81. 'telphone' => input('post.telphone/s'),
  82. 'mycode' => input('post.mycode/s'),
  83. 'tips' => input('post.tips/s'),
  84. 'title' => input('post.title/s'),
  85. 'bonus_types' => input('post.bonus_types/d'),
  86. 'bonus_user_types' => input('post.bonus_user_types/d'),
  87. 'share_ratio_user' => input('post.share_ratio_user/d'),
  88. 'share_ratio' => input('post.share_ratio/f'),
  89. 'price' => input('post.price/f'),
  90. 'share_img' => input('post.share_img/s'),
  91. 'share_title' => input('post.share_title/s'),
  92. 'share_text' => input('post.share_text/s'),
  93. 'music' => input('post.music/s'),
  94. 'note' => input('post.note/s'),
  95. 'img' => input('post.img/s'),
  96. 'imgs' => input('post.imgs/a'),
  97. 'start_time' => input('post.start_time/s'),
  98. 'end_time' => input('post.end_time/s'),
  99. ];
  100. $validate = $this->validate($data,'Unmarket.edit');
  101. if(true !== $validate){
  102. return json(['code'=>0,'msg'=>$validate]);
  103. }
  104. $result = AllwinUnmarket::edit($data);
  105. if($result){
  106. return json(['code'=>200,'url'=>url('manage.unmarket/index'),'msg'=>'操作成功']);
  107. }else{
  108. return json(['code'=>0,'msg'=>'操作失败']);
  109. }
  110. }else{
  111. $condition = [];
  112. $condition['id'] = input('get.id/d');
  113. $condition['member_miniapp_id'] = $this->member_miniapp_id;
  114. $info = AllwinUnmarket::where($condition)->find();
  115. if(!$info){
  116. $this->error("404 NOT FOUND");
  117. }
  118. $info['imgs'] = json_decode($info['imgs'],true);
  119. $view['info'] = $info;
  120. return view()->assign($view);
  121. }
  122. }
  123. //删除
  124. public function delete(){
  125. $id = input('get.id/d');
  126. $result = AllwinUnmarketOrder::where(['share_id' => $id])->find();
  127. if(isset($result)){
  128. return json(['code'=>0,'msg'=>'有订单数据,禁止删除']);
  129. }
  130. $result = AllwinUnmarket::where(['member_miniapp_id' => $this->member_miniapp_id,'id' => $id])->delete();
  131. if($result){
  132. return json(['code'=>200,'msg'=>'操作成功']);
  133. }else{
  134. return json(['code'=>0,'msg'=>'删除失败']);
  135. }
  136. }
  137. /**
  138. * 联盟商家
  139. */
  140. public function store(int $id){
  141. $condition['member_miniapp_id'] = $this->member_miniapp_id;
  142. $condition['union_id'] = $id;
  143. $view['lists'] = AllwinUnmarketStore::where($condition)->order('id desc')->paginate(20);
  144. $view['union_id'] = $id;
  145. $view['pathMaps'] = [
  146. ['name'=>'团购联盟','url' => url('manage.unmarket/index')],
  147. ['name'=>'联盟商家','url' => 'javascript:;'],
  148. ];
  149. return view()->assign($view);
  150. }
  151. /**
  152. * 添加商家
  153. */
  154. public function storeAdd(){
  155. if(request()->isAjax()){
  156. $store_id = input('post.store_id/d');
  157. if(empty($store_id)){
  158. return json(['code'=>0,'msg'=>'未找到好店']);
  159. }
  160. $store = AllwinStore::where(['id' => $store_id])->find();
  161. $data = [
  162. 'union_id' => input('post.union_id/d'),
  163. 'member_miniapp_id' => $this->member_miniapp_id,
  164. 'store_id' => $store_id,
  165. 'name' => $store->name,
  166. 'address' => $store->address,
  167. 'tel' => $store->telphone,
  168. 'end_time' => input('post.endtime/s'),
  169. 'content' => input('post.content/s'),
  170. 'note' => input('post.note/s'),
  171. 'about' => input('post.about/s'),
  172. 'pictext' => input('post.pictext/s'),
  173. 'img' => input('post.img/s'),
  174. 'imgs' => input('post.imgs/a')
  175. ];
  176. $validate = $this->validate($data, 'Unmarket.store');
  177. if(true !== $validate){
  178. return json(['code'=>0,'msg'=>$validate]);
  179. }
  180. $result = AllwinUnmarketStore::edit($data);
  181. if($result){
  182. return json(['code'=>200,'url'=>url('manage.unmarket/store',['id' => $data['union_id']]),'msg'=>'操作成功']);
  183. }else{
  184. return json(['code'=>0,'msg'=>'操作失败']);
  185. }
  186. }else{
  187. $union_id = input('get.union_id/d');
  188. $info = AllwinUnmarket::where(['id' => $union_id])->find();
  189. if(empty($info)){
  190. $this->error("添加所属资源不存在");
  191. }
  192. $view['union'] = $info;
  193. return view()->assign($view);
  194. }
  195. }
  196. /**
  197. * 店铺配置
  198. */
  199. public function storeEdit(){
  200. if(request()->isAjax()){
  201. $store_id = input('post.store_id/d');
  202. if(empty($store_id)){
  203. return json(['code'=>0,'msg'=>'操作失败']);
  204. }
  205. $store = AllwinStore::where(['id' => $store_id])->find();
  206. $data = [
  207. 'id' => input('post.id/d'),
  208. 'union_id' => input('post.union_id/d'),
  209. 'member_miniapp_id' => $this->member_miniapp_id,
  210. 'store_id' => $store_id,
  211. 'name' => $store->name,
  212. 'address' => $store->address,
  213. 'tel' => $store->telphone,
  214. 'end_time' => input('post.endtime/s'),
  215. 'content' => input('post.content/s'),
  216. 'note' => input('post.note/s'),
  217. 'about' => input('post.about/s'),
  218. 'pictext' => input('post.pictext/s'),
  219. 'img' => input('post.img/s'),
  220. 'imgs' => input('post.imgs/a'),
  221. ];
  222. $validate = $this->validate($data,'Unmarket.store');
  223. if(true !== $validate){
  224. return json(['code'=>0,'msg'=>$validate]);
  225. }
  226. $result = AllwinUnmarketStore::edit($data);
  227. if($result){
  228. return json(['code'=>200,'url'=>url('manage.unmarket/store',['id' => $data['union_id']]),'msg'=>'操作成功']);
  229. }else{
  230. return json(['code'=>0,'msg'=>'操作失败']);
  231. }
  232. }else{
  233. $id = input('get.id/d');
  234. $info = AllwinUnmarketStore::where(['member_miniapp_id' => $this->member_miniapp_id])->where(['id' => $id])->find();
  235. if(empty($info)){
  236. $this->error("商家不存在");
  237. }
  238. $view['info'] = $info;
  239. $view['union_id'] = input('get.union_id/d');
  240. $info['imgs'] = json_decode($info['imgs'],true);
  241. return view()->assign($view);
  242. }
  243. }
  244. /**
  245. * 删除商家
  246. */
  247. public function storeDelete(){
  248. $id = input('get.id/d');
  249. $result = AllwinUnmarketStore::where(['member_miniapp_id' => $this->member_miniapp_id,'id' => $id])->delete();
  250. if($result){
  251. return json(['code'=>200,'msg'=>'操作成功']);
  252. }else{
  253. return json(['code'=>0,'msg'=>'删除失败']);
  254. }
  255. }
  256. /**
  257. * 订单裂变
  258. */
  259. public function order(int $id,int $state = 0){
  260. $condition['state'] = $state ? 0: 1;
  261. $condition['member_miniapp_id'] = $this->member_miniapp_id;
  262. $condition['share_id'] = $id;
  263. $view['lists'] = AllwinUnmarketOrder::where($condition)->order('id desc')->paginate(20,false,['query'=>['id'=>$id,'state' => $state]]);
  264. $view['state'] = $state;
  265. $view['id'] = $id;
  266. return view()->assign($view);
  267. }
  268. /**
  269. * 删除订单
  270. */
  271. public function deleteOrder(){
  272. $id = input('get.id/d');
  273. $result = AllwinUnmarketOrder::where(['member_miniapp_id' => $this->member_miniapp_id,'id' => $id])->delete();
  274. if($result){
  275. return json(['code'=>200,'msg'=>'操作成功']);
  276. }else{
  277. return json(['code'=>0,'msg'=>'删除失败']);
  278. }
  279. }
  280. /**
  281. * 核销列表
  282. */
  283. public function Verification(int $id){
  284. $view['info'] = AllwinUnmarket::where(['id' => $id])->field('title,note')->find();
  285. if(empty($view['info'])){
  286. $this->error("活动不存在");
  287. }
  288. $condition['union_id'] = $id;
  289. $condition['member_miniapp_id'] = $this->member_miniapp_id;
  290. $view['lists'] = AllwinUnmarketVerif::where($condition)->order('id desc')->paginate(20);
  291. return view()->assign($view);
  292. }
  293. /**
  294. * 预约商家
  295. */
  296. public function Booking(){
  297. $condition['member_miniapp_id'] = $this->member_miniapp_id;
  298. $view['lists'] = AllwinUnmarketBooking::where($condition)->order('id desc')->paginate(20);
  299. return view()->assign($view);
  300. }
  301. /**
  302. * 删除商家联系
  303. */
  304. public function deleteBooking(){
  305. $id = input('get.id/d');
  306. $result = AllwinUnmarketBooking::where(['member_miniapp_id' => $this->member_miniapp_id,'id' => $id])->delete();
  307. if($result){
  308. return json(['code'=>200,'msg'=>'操作成功']);
  309. }else{
  310. return json(['code'=>0,'msg'=>'删除失败']);
  311. }
  312. }
  313. }