Trade.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <?php
  2. namespace app\shop\controller;
  3. use app\common\controller\Frontend;
  4. class Trade extends Frontend{
  5. protected $noNeedLogin = [''];
  6. protected $noNeedRight = '*';
  7. protected $layout = '';
  8. public function _initialize()
  9. {
  10. parent::_initialize();
  11. }
  12. /* 分类 */
  13. function index()
  14. {
  15. $info=db('user')->where(['id'=>$this->auth->id])->find();
  16. $total1=0;$total2=0;
  17. $total1=db('detailed_bonus')->where(['userid'=>$info['id'],'type'=>['in','16,17,18']])->sum('money');
  18. $total2=db('detailed_bonus')->where(['userid'=>$info['id'],'type'=>19])->sum('money');
  19. $this->view->assign([
  20. "user"=>$info,
  21. 'total1'=>$total1,
  22. 'total2'=>$total2
  23. ]);
  24. return $this->fetch();
  25. }
  26. function orders()
  27. {
  28. return $this->fetch();
  29. }
  30. function editorder()
  31. {
  32. $id=input('id');
  33. $trade=db('trade')->where(['id'=>$id])->find();
  34. $this->view->assign([
  35. "trade"=>$trade,
  36. ]);
  37. return $this->fetch();
  38. }
  39. /*全部*/
  40. function tradelist()
  41. {
  42. return $this->fetch();
  43. }
  44. /*待付款订单*/
  45. function trade1()
  46. {
  47. $list=db('trade')->where(['relevant_userid'=>$this->auth->id,'status'=>1])->select();
  48. foreach ($list as &$v)
  49. {
  50. $goods=db('goods')->where(['id'=>$v['goodsid']])->find();
  51. $v['goods']=$goods;
  52. $v['flag']=0;
  53. $v['selluser']=get_user_info($v['userid'],'nickname','mobile');
  54. $v['buyuser']=get_user_info($v['relevant_userid'],'nickname','mobile');
  55. if($v['userid']== $this->auth->id)
  56. {
  57. $v['flag']=1;
  58. }else{
  59. $v['flag']=2;
  60. }
  61. }
  62. $this->view->assign([
  63. 'list'=>$list,
  64. ]);
  65. return $this->fetch();
  66. }
  67. /*待确认*/
  68. function trade2()
  69. {
  70. $list=db('trade')->where(['userid'=>$this->auth->id,'status'=>2])->select();
  71. foreach ($list as &$v)
  72. {
  73. $goods=db('goods')->where(['id'=>$v['goodsid']])->find();
  74. $v['goods']=$goods;
  75. $v['flag']=0;
  76. $v['selluser']=get_user_info($v['userid'],'nickname','mobile');
  77. $v['buyuser']=get_user_info($v['relevant_userid'],'nickname','mobile');
  78. if($v['userid']== $this->auth->id)
  79. {
  80. $v['flag']=1;
  81. }else{
  82. $v['flag']=2;
  83. }
  84. }
  85. $this->view->assign([
  86. 'list'=>$list,
  87. ]);
  88. return $this->fetch();
  89. }
  90. function trade4()
  91. {
  92. return $this->fetch();
  93. }
  94. function trade5()
  95. {
  96. $list=db('trade')->where(['userid|relevant_userid'=>$this->auth->id,'status'=>-1])->select();
  97. foreach ($list as &$v)
  98. {
  99. $goods=db('goods')->where(['id'=>$v['goodsid']])->find();
  100. $v['goods']=$goods;
  101. $v['flag']=0;
  102. $v['selluser']=get_user_info($v['userid'],'nickname','mobile');
  103. $v['buyuser']=get_user_info($v['relevant_userid'],'nickname','mobile');
  104. if($v['userid']== $this->auth->id)
  105. {
  106. $v['flag']=1;
  107. }elseif($v['relevant_userid'] == $this->auth->id)
  108. {
  109. $v['flag']=2;
  110. }
  111. }
  112. $this->view->assign([
  113. 'list'=>$list,
  114. ]);
  115. return $this->fetch();
  116. }
  117. /**/
  118. function trade3()
  119. {
  120. $list=db('trade')->where(['relevant_userid'=>$this->auth->id,'status'=>3,'issell'=>[['egt',0],['elt',2]]])->select();
  121. foreach ($list as &$v)
  122. {
  123. $goods=db('goods')->where(['id'=>$v['goodsid']])->find();
  124. $v['goods']=$goods;
  125. $v['flag']=0;
  126. $v['selluser']=get_user_info($v['userid'],'nickname','mobile');
  127. $v['buyuser']=get_user_info($v['relevant_userid'],'nickname','mobile');
  128. if($v['userid']== $this->auth->id)
  129. {
  130. $v['flag']=1;
  131. }elseif($v['relevant_userid'] == $this->auth->id)
  132. {
  133. $v['flag']=2;
  134. }
  135. }
  136. $this->view->assign([
  137. 'list'=>$list,
  138. ]);
  139. return $this->fetch();
  140. }
  141. function tj()
  142. {
  143. $list=db('studio')->where(['refereeid'=>$this->auth->stuid,'status'=>1])->select();
  144. $sid=input('sid');
  145. if($sid>0)
  146. {
  147. $map['stuid']=$sid;
  148. }else{
  149. $map['stuid']=0;
  150. }
  151. $time=input('starttime');
  152. if(empty($time))
  153. {
  154. $start=strtotime('today')-60*60*24*5;
  155. $map['ctime']=['gt',$start];
  156. }else{
  157. $start=strtotime($time);
  158. $end=$start+60*60*24;
  159. $map['ctime']=[['egt',$start],['lt',$end]];
  160. }
  161. ##订单数
  162. $total=db('trade')->where($map)->count();
  163. #总金额
  164. $totalnums=db('trade')->where($map)->sum('nums');
  165. #总上架费
  166. $totalfee=db('trade')->where($map)->sum('fee');
  167. $this->view->assign([
  168. 'list'=>$list,
  169. 'sid'=>$sid,
  170. 'starttime'=>$time,
  171. 'total'=>$total,
  172. 'totalnums'=>$totalnums,
  173. 'totalfee'=>$totalfee,
  174. ]);
  175. return $this->fetch();
  176. }
  177. /*导出*/
  178. function toexport()
  179. {
  180. $name=date('Y-m-d-H-i-s');
  181. $sid=input('sid');
  182. if($sid>0)
  183. {
  184. $map['stuid']=$sid;
  185. }
  186. $time=input('starttime');
  187. if(empty($time))
  188. {
  189. $start=strtotime('today')-60*60*24*5;
  190. $map['ctime']=['gt',$start];
  191. }else{
  192. $start=strtotime($time);
  193. $end=$start+60*60*24;
  194. $map['ctime']=[['egt',$start],['lt',$end]];
  195. }
  196. ##订单数
  197. $data_list=db('trade')->where($map)->order('id asc')->select();
  198. Vendor('PHPExcel.PHPExcel.IOFactory');
  199. $objPHPExcel = new \PHPExcel();
  200. $objPHPExcel->getActiveSheetIndex(0);
  201. $objPHPExcel->getActiveSheet()->setTitle(iconv('gbk', 'utf-8', 'Sheet'));
  202. // 设置默认字体和大小
  203. $objPHPExcel->getDefaultStyle()->getFont()->setName(iconv('gbk', 'utf-8', ''));
  204. $objPHPExcel->getDefaultStyle()->getFont()->setSize(11);
  205. $styleArray = array(
  206. 'font' => array(
  207. 'bold' => true,
  208. 'color'=>array(
  209. 'argb' => 'ffffffff',
  210. )
  211. ),
  212. 'borders' => array (
  213. 'outline' => array (
  214. 'style' => \PHPExcel_Style_Border::BORDER_THIN,
  215. 'color' => array ('argb' => 'FF000000'), //设置border颜色
  216. )
  217. )
  218. );
  219. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
  220. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
  221. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
  222. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
  223. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
  224. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
  225. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
  226. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
  227. $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(20);
  228. $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(20);
  229. $objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(20);
  230. $objPHPExcel->getActiveSheet()->getStyle('A1:K1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
  231. $objPHPExcel->getActiveSheet()->getStyle('A1:K1')->getFill()->getStartColor()->setARGB('333399');
  232. $objPHPExcel->getActiveSheet()
  233. ->setCellValue('A1', '藏品名称')
  234. ->setCellValue('B1', '字画编号')
  235. ->setCellValue('C1', '藏馆')
  236. ->setCellValue('D1', '出售人')
  237. ->setCellValue('E1', '购买人')
  238. ->setCellValue('F1', '订单金额')
  239. ->setCellValue('G1', '上架费')
  240. ->setCellValue('H1', '状态')
  241. ->setCellValue('I1', '抢单时间')
  242. ->setCellValue('J1', '支付时间')
  243. ->setCellValue('K1', '确认时间');
  244. $objPHPExcel->getActiveSheet()->getStyle('A1:K1')->applyFromArray($styleArray);
  245. foreach ($data_list as $k=>$v){
  246. $i=$k+2;//注意表头
  247. $objPHPExcel->getActiveSheet()
  248. ->setCellValue('A'.$i,get_table_column('goods',$v['goodsid'],'title'))
  249. ->setCellValue('B'.$i, get_table_column('goods',$v['goodsid'],'description'))
  250. ->setCellValue('C'.$i, get_table_column('studio',$v['stuid'],'name'))
  251. ->setCellValue('D'.$i, get_user_info($v['userid'],'nickname','mobile'))
  252. ->setCellValue('E'.$i, get_user_info($v['relevant_userid'],'nickname','mobile'))
  253. ->setCellValue('F'.$i, $v['nums'])
  254. ->setCellValue('G'.$i, $v['fee'])
  255. ->setCellValue('H'.$i, '已完成')
  256. ->setCellValue('I'.$i, date('Y-m-d H:i:s',$v['ctime']))
  257. ->setCellValue('J'.$i, date('Y-m-d H:i:s',$v['pay_time']))
  258. ->setCellValue('K'.$i, date('Y-m-d H:i:s',$v['confirm_time']));
  259. }
  260. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel5');
  261. // 从浏览器直接输出$filename
  262. header('Content-Type:application/csv;charset=UTF-8');
  263. header("Pragma: public");
  264. header("Expires: 0");
  265. header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
  266. header("Content-Type:application/force-download");
  267. header("Content-Type:application/vnd.ms-excel;");
  268. header("Content-Type:application/octet-stream");
  269. header("Content-Type:application/download");
  270. header('Content-Disposition: attachment;filename="'.$name.'.xls"');
  271. header("Content-Transfer-Encoding:binary");
  272. $objWriter->save('php://output');
  273. }
  274. function ownchange()
  275. {
  276. $goodsid=input('goodsid');
  277. $goodsinfo=db('goods')->where(['id'=>$goodsid])->find();
  278. $owner=db('user')->where(['id'=>$goodsinfo['userid']])->find();
  279. $this->view->assign([
  280. 'goodsinfo'=>$goodsinfo,
  281. 'owner'=>$owner,
  282. ]);
  283. return $this->fetch();
  284. }
  285. function changestudio()
  286. {
  287. $goodsid=input('goodsid');
  288. $goodsinfo=db('goods')->where(['id'=>$goodsid])->find();
  289. $studiolist=db('studio')->where(['status'=>1])->select();
  290. $this->view->assign([
  291. 'goodsinfo'=>$goodsinfo,
  292. 'slist'=>$studiolist,
  293. ]);
  294. return $this->fetch();
  295. }
  296. function changelist()
  297. {
  298. $type=input('type');
  299. if(empty($type))
  300. {
  301. $type=1;
  302. }
  303. $this->view->assign([
  304. 'type'=>$type,
  305. ]);
  306. return $this->fetch();
  307. }
  308. function yuyue()
  309. {
  310. $sid=input('sid');
  311. $sinfo=db('studio')->where(['id'=>$sid])->find();
  312. if(time()>strtotime(date("Y-m-d {$sinfo['start']}")) && time()< strtotime(date("Y-m-d {$sinfo['end']}")) )
  313. {
  314. $status='营业中';
  315. }elseif(time()< strtotime(date("Y-m-d {$sinfo['start']}"))){
  316. $status='停业中';
  317. }elseif(time() > strtotime(date("Y-m-d {$sinfo['end']}"))){
  318. $status='停业中';
  319. }
  320. $this->view->assign([
  321. 'sid'=>$sid,
  322. 'studio'=>$sinfo,
  323. 'status'=>$status
  324. ]);
  325. return $this->fetch();
  326. }
  327. function yuyuecode()
  328. {
  329. $list=db('trade')->where(['relevant_userid'=>$this->auth->id,'status'=>0])->select();
  330. foreach ($list as &$v)
  331. {
  332. $goods=db('goods')->where(['id'=>$v['goodsid']])->find();
  333. $v['goods']=$goods;
  334. }
  335. $this->view->assign([
  336. 'list'=>$list,
  337. ]);
  338. return $this->fetch();
  339. }
  340. function hostgoods()
  341. {
  342. return $this->fetch();
  343. }
  344. function hostappoint()
  345. {
  346. $list=db('trade')->where(['stuid'=>$this->auth->stuid,'status'=>0])->select();
  347. foreach ($list as &$v)
  348. {
  349. $goods=db('goods')->where(['id'=>$v['goodsid']])->find();
  350. $v['goods']=$goods;
  351. }
  352. $this->view->assign([
  353. 'list'=>$list,
  354. ]);
  355. return $this->fetch();
  356. }
  357. function sethost()
  358. {
  359. $sinfo=db('studio')->where(['id'=>$this->auth->stuid])->find();
  360. $this->view->assign([
  361. 'studio'=>$sinfo,
  362. ]);
  363. return $this->fetch();
  364. }
  365. function managergoods()
  366. {
  367. $this->view->assign([
  368. 'type'=>input('type')==''?1:input('type'),
  369. ]);
  370. return $this->fetch();
  371. }
  372. function setuserappoint()
  373. {
  374. $sinfo=db('studio')->where(['id'=>$this->auth->stuid])->find();
  375. $this->view->assign([
  376. 'studio'=>$sinfo,
  377. ]);
  378. return $this->fetch();
  379. }
  380. function viewonsale()
  381. {
  382. $type=input('type');
  383. if(empty($type))
  384. {
  385. $type=0;
  386. }
  387. $this->view->assign('type',$type);
  388. return $this->fetch();
  389. }
  390. /*交易详情*/
  391. function showtrade()
  392. {
  393. $id=input('id');
  394. $trade=db('trade')->where(['id'=>$id])->find();
  395. $goods= db('goods')->where(['id'=>$trade['goodsid']])->find();
  396. $selluser=db('user')->where(['id'=>$trade['userid']])->find();
  397. $buyuser=db('user')->where(['id'=>$trade['relevant_userid']])->find();
  398. $this->view->assign([
  399. 'selluser'=>$selluser,
  400. 'info'=>$trade,
  401. 'goods'=>$goods,
  402. 'buyuser'=>$buyuser,
  403. ]);
  404. return $this->fetch();
  405. }
  406. function mydraw()
  407. {
  408. $type=input('type');
  409. $this->view->assign([
  410. 'type'=>$type]);
  411. return $this->fetch();
  412. }
  413. /*申诉*/
  414. function appeal()
  415. {
  416. $id=input('id');
  417. $this->view->assign('id',$id);
  418. return $this->fetch();
  419. }
  420. /*待支付*/
  421. function topay()
  422. {
  423. $id=input('id');
  424. $trade=db('trade')->where(['id'=>$id])->find();
  425. $goods= db('goods')->where(['id'=>$trade['goodsid']])->find();
  426. $selluser=db('user')->where(['id'=>$trade['userid']])->find();
  427. $level=get_user_data($this->auth->id,'level');
  428. $feeCf=db('bonus_config')->where(['config_type'=>3,'user_level'=>$level])->find();
  429. $bcf=db('bonus_config')->where(['id'=>1])->find();
  430. $rtx=$bcf['value'];
  431. $this->view->assign([
  432. 'selluser'=>$selluser,
  433. 'info'=>$trade,
  434. 'goods'=>$goods,
  435. 'rtx'=>$rtx,
  436. ]);
  437. return $this->fetch();
  438. }
  439. /*冻结goods*/
  440. function djgoods()
  441. {
  442. $list=db('goods')->where(['userid'=>$this->auth->id,'isdj'=>1,'istj'=>1])->order('id asc')->select();
  443. $this->view->assign([
  444. 'list'=>$list,
  445. ]);
  446. return $this->fetch();
  447. }
  448. /*冻结goods*/
  449. function djedgoods()
  450. {
  451. $list=db('goods')->where(['userid'=>$this->auth->id,'isdj'=>0,'istj'=>1])->order('id desc')->select();
  452. $this->view->assign([
  453. 'list'=>$list,
  454. ]);
  455. return $this->fetch();
  456. }
  457. }