Trade.php 18 KB

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