ShopapplyController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <?php
  2. /**
  3. * 店铺申请
  4. */
  5. namespace app\admin\controller;
  6. use cmf\controller\AdminBaseController;
  7. use think\facade\Db;
  8. class ShopapplyController extends AdminbaseController {
  9. protected function getStatus($k=''){
  10. $status=array(
  11. '0'=>'待处理',
  12. '1'=>'审核成功',
  13. '2'=>'审核失败',
  14. );
  15. if($k===''){
  16. return $status;
  17. }
  18. return isset($status[$k])?$status[$k]:'';
  19. }
  20. function index(){
  21. $data = $this->request->param();
  22. $map=[];
  23. $map[]=['uid','<>',1];
  24. $start_time=isset($data['start_time']) ? $data['start_time']: '';
  25. $end_time=isset($data['end_time']) ? $data['end_time']: '';
  26. if($start_time!=""){
  27. $map[]=['addtime','>=',strtotime($start_time)];
  28. }
  29. if($end_time!=""){
  30. $map[]=['addtime','<=',strtotime($end_time) + 60*60*24];
  31. }
  32. $status=isset($data['status']) ? $data['status']: '';
  33. if($status!=''){
  34. $map[]=['status','=',$status];
  35. }
  36. $uid=isset($data['uid']) ? $data['uid']: '';
  37. if($uid!=''){
  38. $map[]=['uid','=',$uid];
  39. }
  40. $lists = Db::name("shop_apply")
  41. ->where($map)
  42. ->order("addtime DESC")
  43. ->paginate(20);
  44. $lists->each(function($v,$k){
  45. //$v['thumb']=get_upload_path($v['thumb']);
  46. $v['userinfo']= getUserInfo($v['uid']);
  47. $v['tel']= m_s($v['uid']);
  48. $v['cardno']=m_s($v['cardno']);
  49. $v['phone']=m_s($v['phone']);
  50. $v['classname']='';
  51. //获取商家经营类目
  52. $class_list=Db::name("seller_goods_class")->where("uid={$v['uid']}")->select()->toArray();
  53. $num=count($class_list);
  54. foreach ($class_list as $k1 => $v1) {
  55. $gc_name=Db::name("shop_goods_class")->where("gc_id={$v1['goods_classid']}")->value('gc_name');
  56. $v['classname'].=$gc_name;
  57. if($num>1&&$k1<($num-1)){
  58. $v['classname'].=' | ';
  59. }
  60. }
  61. return $v;
  62. });
  63. $lists->appends($data);
  64. $page = $lists->render();
  65. //判断平台店铺是否申请
  66. $platform_apply=1;
  67. $platform_info=Db::name("shop_apply")->where("uid=1")->find();
  68. if(!$platform_info){
  69. $platform_apply=0;
  70. }
  71. $this->assign('lists', $lists);
  72. $this->assign("page", $page);
  73. $this->assign("status", $this->getStatus());
  74. $this->assign("platform_apply", $platform_apply);
  75. return $this->fetch();
  76. }
  77. function del(){
  78. $id = $this->request->param('id', 0, 'intval');
  79. $rs = DB::name('shop_apply')->where("uid={$id}")->delete();
  80. if(!$rs){
  81. $this->error("删除失败!");
  82. }
  83. $action="删除店铺申请:{$id}";
  84. setAdminLog($action);
  85. //删除店铺总评分记录
  86. Db::name("shop_points")->where("shop_uid={$id}")->delete();
  87. //删除店铺商品
  88. Db::name("shop_goods")->where("uid={$id}")->delete();
  89. //删除收藏商品
  90. Db::name("user_goods_collect")->where("goodsuid={$id}")->delete();
  91. $this->success("删除成功!",url("shopapply/index"));
  92. }
  93. function edit(){
  94. $id = $this->request->param('id', 0, 'intval');
  95. $data=Db::name('shop_apply')
  96. ->where("uid={$id}")
  97. ->find();
  98. if(!$data){
  99. $this->error("信息错误");
  100. }
  101. //$data['thumb']= get_upload_path($data['thumb']);
  102. $data['certificate']= get_upload_path($data['certificate']);
  103. //$data['license']= get_upload_path($data['license']);
  104. $data['other']= get_upload_path($data['other']);
  105. $data['userinfo']= getUserInfo($data['uid']);
  106. //获取一级店铺分类
  107. $oneGoodsClass=getcaches("oneGoodsClass");
  108. $oneGoodsClass=[];
  109. if(empty($oneGoodsClass)){
  110. $oneGoodsClass=Db::name("shop_goods_class")->field("gc_id,gc_name,gc_isshow")->where("gc_parentid=0")->order("gc_sort")->select()->toArray();
  111. setcaches("oneGoodsClass",$oneGoodsClass);
  112. }
  113. //获取用户的经营类目
  114. $seller_class_arr=Db::name("seller_goods_class")->where("uid={$data['uid']}")->select()->toArray();
  115. $seller_class_arr=array_column($seller_class_arr, 'goods_classid');
  116. foreach($oneGoodsClass as $ks=>$vs){
  117. if(in_array($vs['gc_id'],$seller_class_arr)){
  118. $oneGoodsClass[$ks]['gc_isshow']=3; //已存在的类目
  119. }
  120. }
  121. $seller_class=implode(",",$seller_class_arr);
  122. $this->assign('data', $data);
  123. $this->assign('oneGoodsClass', $oneGoodsClass);
  124. $this->assign('seller_class', $seller_class);
  125. $this->assign("status", $this->getStatus());
  126. return $this->fetch();
  127. }
  128. function editPost(){
  129. if ($this->request->isPost()) {
  130. $data = $this->request->param();
  131. $classids=isset($data['classids'])?$data['classids']:[];
  132. $count=count($classids);
  133. if($count<1){
  134. $this->error("请选择经营类目");
  135. }
  136. $uid=$data['uid'];
  137. $order_percent=$data['order_percent'];
  138. if($order_percent<0||!is_numeric($order_percent)||$order_percent>100){
  139. $this->error("请填写0-100之间的整数");
  140. }
  141. if(floor($order_percent)!=$order_percent){
  142. $this->error("请填写0-100之间的整数");
  143. }
  144. unset($data['classids']);
  145. $shop_status=$data['status'];
  146. $reason=$data['reason'];
  147. if($shop_status==2){ //审核失败
  148. if(trim($reason)==""){
  149. $this->error("请填写审核失败原因");
  150. }
  151. }
  152. $data['uptime']=time();
  153. $rs = DB::name('shop_apply')->update($data);
  154. if($rs===false){
  155. $this->error("修改失败!");
  156. }
  157. //更新用户经营类目
  158. Db::name("seller_goods_class")->where("uid={$uid}")->delete();
  159. foreach ($classids as $k => $v) {
  160. //获取一级分类的状态
  161. $status=Db::name("shop_goods_class")->where("gc_id={$v}")->value('gc_isshow');
  162. $data1=array(
  163. 'uid'=>$uid,
  164. 'goods_classid'=>$v,
  165. 'status'=>$status
  166. );
  167. Db::name("seller_goods_class")->where("uid={$uid}")->insert($data1);
  168. }
  169. if($shop_status!=1){
  170. //将店铺内上架的商品下架
  171. Db::name("shop_goods")->where("uid={$uid} and status=1")->update(array('status'=>-2));
  172. }
  173. $action="修改店铺信息";
  174. if($shop_status>0){
  175. $title='';
  176. if($shop_status==1){ //审核通过
  177. $title='你的店铺审核已通过。';
  178. }else if($shop_status==2){ //审核失败
  179. $title='你的店铺审核失败。';
  180. if($reason){
  181. $title.='失败原因:'.$reason;
  182. }
  183. }
  184. $text="店铺审核提醒";
  185. $result1=addSysytemInfo($uid,$text,$title);
  186. if($result1!==false){
  187. //发送腾讯IM
  188. txMessageIM($text,$uid);
  189. }
  190. $action.=$title;
  191. }
  192. setAdminLog($action);
  193. $this->success("修改成功!");
  194. }
  195. }
  196. //平台自营店铺信息
  197. function platformedit(){
  198. $platform_info=Db::name("shop_apply")->where("uid=1")->find();
  199. if(!$platform_info){
  200. $platform_info=[
  201. 'uid'=>1,
  202. 'username'=>'',
  203. 'cardno'=>'',
  204. 'contact'=>'',
  205. 'country_code'=>'86',
  206. 'phone'=>'',
  207. 'province'=>'北京市',
  208. 'city'=>'北京市',
  209. 'area'=>'朝阳区',
  210. 'address'=>'',
  211. 'service_phone'=>'',
  212. 'receiver'=>'',
  213. 'receiver_phone'=>'',
  214. 'receiver_province'=>'北京市',
  215. 'receiver_city'=>'北京市',
  216. 'receiver_area'=>'朝阳区',
  217. 'receiver_address'=>'',
  218. 'certificate'=>'',
  219. 'other'=>'',
  220. 'addtime'=>time(),
  221. 'uptime'=>time(),
  222. 'status'=>1,
  223. ];
  224. }
  225. $this->assign("platform_info",$platform_info);
  226. return $this->fetch();
  227. }
  228. function platformeditPost(){
  229. $data=$this->request->param();
  230. $username=$data['username'];
  231. $cardno=$data['cardno'];
  232. $contact=$data['contact'];
  233. $phone=$data['phone'];
  234. /*$province=$data['province'];
  235. $city=$data['city'];
  236. $area=$data['area'];
  237. $address=$data['address'];*/
  238. $service_phone=$data['service_phone'];
  239. $receiver_phone=$data['receiver_phone'];
  240. $receiver_province=$data['receiver_province'];
  241. $receiver_city=$data['receiver_city'];
  242. $receiver_area=$data['receiver_area'];
  243. $receiver=$data['receiver'];
  244. $receiver_address=$data['receiver_address'];
  245. $certificate=$data['certificate'];
  246. $other=$data['other'];
  247. if(!$username){
  248. $this->error("请填写姓名");
  249. }
  250. if(!$cardno){
  251. $this->error("请填写身份证号");
  252. }
  253. $check_card=checkCardNo($cardno);
  254. if(!$check_card){
  255. $this->error("请确认身份证号的正确性");
  256. }
  257. if(!$contact){
  258. $this->error("请填写经营者联系人");
  259. }
  260. if(!$phone){
  261. $this->error("请填写经营者联系电话");
  262. }
  263. /*if(!$province){
  264. $this->error("请填写经营者所在省份");
  265. }
  266. if(!$city){
  267. $this->error("请填写经营者所在市");
  268. }
  269. if(!$area){
  270. $this->error("请填写经营者所在地区");
  271. }
  272. if(!$address){
  273. $this->error("请填写经营者详细地址");
  274. }*/
  275. if(!$service_phone){
  276. $this->error("请填写客服电话");
  277. }
  278. if(!$receiver_phone){
  279. $this->error("请填写退货收货人手机号");
  280. }
  281. if(!$receiver_province){
  282. $this->error("请选择退货收货人省份");
  283. }
  284. if(!$receiver_city){
  285. $this->error("请选择退货收货人市");
  286. }
  287. if(!$receiver_area){
  288. $this->error("请选择退货收货人地区");
  289. }
  290. if(!$receiver_address){
  291. $this->error("请选择退货收货人详细地址");
  292. }
  293. if(!$receiver){
  294. $this->error("请填写退货收货人");
  295. }
  296. if(!$certificate){
  297. $this->error("请上传营业执照");
  298. }
  299. if(!$other){
  300. $this->error("请上传其他证件");
  301. }
  302. $platform_info=Db::name("shop_apply")->where("uid=1")->find();
  303. if(!$platform_info){
  304. $data['province']=$data['receiver_province'];
  305. $data['city']=$data['receiver_city'];
  306. $data['area']=$data['receiver_area'];
  307. $data['address']=$data['receiver_address'];
  308. $data['uid']=1;
  309. $data['status']=1;
  310. $data['addtime']=time();
  311. $res=Db::name("shop_apply")->insert($data);
  312. $shop_points_arr=array(
  313. 'shop_uid'=>1,
  314. 'evaluate_total'=>0,
  315. 'quality_points_total'=>0,
  316. 'service_points_total'=>0,
  317. 'express_points_total'=>0
  318. );
  319. Db::name("shop_points")->insert($shop_points_arr);
  320. }else{
  321. $data['uptime']=time();
  322. $res=Db::name("shop_apply")->where("uid=1")->update($data);
  323. }
  324. if($res===false){
  325. $this->error("平台自营店铺信息设置失败!");
  326. }
  327. $this->success("平台自营店铺信息设置成功!");
  328. }
  329. }