Trade.php 16 KB

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