Trade.php 16 KB

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