Goods.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. <?php
  2. namespace app\store\controller;
  3. use app\common\library\PHPExcelService;
  4. use library\Controller;
  5. use think\cache\driver\Redis;
  6. use think\Db;
  7. /**
  8. * 售卖商品
  9. * Class Goods
  10. * @package app\store\controller
  11. */
  12. class Goods extends Controller
  13. {
  14. /**
  15. * 绑定数据表
  16. * @var string
  17. */
  18. protected $table = 'store_collection';
  19. protected $table2 = 'store_box';
  20. /**
  21. * 售卖商品列表
  22. * @auth true
  23. * @menu true
  24. * @throws \think\Exception
  25. * @throws \think\db\exception\DataNotFoundException
  26. * @throws \think\db\exception\ModelNotFoundException
  27. * @throws \think\exception\DbException
  28. * @throws \think\exception\PDOException
  29. */
  30. public function index()
  31. {
  32. checkCollectionState();
  33. $this->title = '售卖藏品管理';
  34. $query = $this->_query($this->table)->where('is_deleted',0)->like('name');
  35. $query->dateBetween('create_at')->whereIn('type','1,3')->order('id desc')->page();
  36. }
  37. /**
  38. * 数据列表处理
  39. * @auth true
  40. * @menu true
  41. * @param array $data
  42. * @throws \think\db\exception\DataNotFoundException
  43. * @throws \think\db\exception\ModelNotFoundException
  44. * @throws \think\exception\DbException
  45. */
  46. protected function _index_page_filter(&$data)
  47. {
  48. foreach ($data as &$v){
  49. $checksell = $this->checkSellTime($v['id']);
  50. if (!$checksell){
  51. $v['is_save'] = 0;
  52. }else{
  53. $v['is_save'] = 1;
  54. }
  55. $v['zz']=Db::table('hash')->where('goods_id',$v['id'])->count();
  56. $now_inventory = getCollectionInventory($v['id']);
  57. $v['now_inventory'] = $now_inventory<=0 ? 0 : $now_inventory;
  58. $v['shengyu'] = Db::name('hash')->where('goods_id',$v['id'])->where('status',0)->count();
  59. }
  60. }
  61. /**
  62. * 添加商品
  63. * @auth true
  64. * @menu true
  65. * @throws \think\Exception
  66. * @throws \think\db\exception\DataNotFoundException
  67. * @throws \think\db\exception\ModelNotFoundException
  68. * @throws \think\exception\DbException
  69. * @throws \think\exception\PDOException
  70. */
  71. public function add()
  72. {
  73. $this->title = '添加藏品';
  74. $this->_form($this->table, 'form');
  75. }
  76. /**
  77. * 编辑商品
  78. * @auth true
  79. * @menu true
  80. * @throws \think\Exception
  81. * @throws \think\db\exception\DataNotFoundException
  82. * @throws \think\db\exception\ModelNotFoundException
  83. * @throws \think\exception\DbException
  84. * @throws \think\exception\PDOException
  85. */
  86. function edit()
  87. {
  88. $this->title = '编辑商品';
  89. $id = $this->request->get('id');
  90. $checksell = $this->checkSellTime($id);
  91. //if (!$checksell) $this->error('藏品已经开始抢购或已过期,无法修改');
  92. $this->_form($this->table, 'form');
  93. }
  94. /**
  95. * 表单数据处理
  96. * @auth true
  97. * @menu true
  98. * @param array $data
  99. */
  100. protected function _form_filter(&$data)
  101. {
  102. if($this->request->post()){
  103. if (isset($data['id']) || !empty($data['id'])){
  104. $checksell = $this->checkSellTime($data['id']);
  105. //if (!$checksell) $this->error('藏品已经开始抢购或已过期,无法修改');
  106. }
  107. if ($data['cover'] == '') $this->error('请上传藏品图片');
  108. if ($data['price']<=0) $this->error('藏品价格错误');
  109. if ($data['auth_img'] == '') $this->error('请上传作者头像');
  110. if ($data['describe'] == '') $this->error('请上传商品描述');
  111. if ($data['buy_count']<1) $this->error('限购数量不能小于1');
  112. //if ($data['share_img'] == '') $this->error('请上传分享二维码');
  113. $data['date'] = date('Y-m-d',strtotime($data['sell_time']));
  114. if (isset($data['id'])){
  115. $buy_count = Db::name('store_order_info')
  116. ->whereIn('status','1,3')
  117. ->where('c_id',$data['id'])
  118. ->count();
  119. }else{
  120. $buy_count = 0;
  121. }
  122. $data['now_inventory'] = $data['inventory']-$buy_count;
  123. $arr = explode('.',$data['detail_img']);
  124. $data['format'] = end($arr);
  125. //var_dump($data['is_pedestal']);exit();
  126. }else{
  127. if (!empty($data)){
  128. $data['covers'] = $data['cover'];
  129. $data['auth_imgs'] = $data['auth_img'];
  130. $data['describes'] = $data['describe'];
  131. $data['share_imgs'] = $data['share_img'];
  132. }
  133. }
  134. }
  135. /**
  136. * 处理成功回调
  137. */
  138. public function _form_result($result,$data){
  139. if ($result) {
  140. setCollectionInfoHash($result);
  141. $redis = new Redis();
  142. $count = Db::name($this->table)->where('id',$result)->value('now_inventory');
  143. $redis->set('collection_count_'.$result,$count);
  144. $this->success('操作成功',url('/#/store/goods/index'));
  145. }
  146. }
  147. /**
  148. * @auth true
  149. * @menu true
  150. * 商品上架
  151. */
  152. public function up()
  153. {
  154. $data = $this->request->post();
  155. checkCollectionState($data['id']);
  156. if (Db::name($this->table)->where('id',$data['id'])->update(['status'=>1])){
  157. setCollectionInfoHash($data['id']);
  158. $this->success('恭喜您,数据更新成功');
  159. }else{
  160. $this->error('数据更新失败');
  161. }
  162. }
  163. /**
  164. * @auth true
  165. * @menu true
  166. * 商品下架
  167. */
  168. public function down()
  169. {
  170. $data = $this->request->post();
  171. if (Db::name($this->table)->where('id',$data['id'])->update(['status'=>0])){
  172. setCollectionInfoHash($data['id']);
  173. $this->success('恭喜您,数据更新成功');
  174. }else{
  175. $this->error('数据更新失败');
  176. }
  177. //$this->_save($this->table, ['status' => '0']);
  178. }
  179. /**
  180. * @auth true
  181. * @menu true
  182. * 商品删除
  183. */
  184. public function del()
  185. {
  186. $data = $this->request->post();
  187. if (Db::name($this->table)->where('id',$data['id'])->update(['is_deleted'=>1])){
  188. setCollectionInfoHash($data['id']);
  189. $this->success('恭喜您,数据更新成功');
  190. }else{
  191. $this->error('数据更新失败');
  192. }
  193. //$this->_save($this->table, ['is_deleted' => '1']);
  194. }
  195. // public function _save_result($result){
  196. // if ($result){
  197. // setCollectionInfoHash($result);
  198. // }
  199. // }
  200. //判断是否已经抢购开始
  201. function checkSellTime($id){
  202. $sell_time = Db::name($this->table)->where('id',$id)->value('sell_time');
  203. $advance_minutes = getAdvanceMinutes();
  204. if ($advance_minutes>0){
  205. $sell_time = strtotime($sell_time)-($advance_minutes*60);
  206. }else{
  207. $sell_time = strtotime($sell_time);
  208. }
  209. if ($sell_time<=time()) return false;
  210. return true;
  211. }
  212. /**
  213. * 赠送商品
  214. * @auth true
  215. * @menu true
  216. * @throws \think\Exception
  217. * @throws \think\db\exception\DataNotFoundException
  218. * @throws \think\db\exception\ModelNotFoundException
  219. * @throws \think\exception\DbException
  220. * @throws \think\exception\PDOException
  221. */
  222. public function send(){
  223. if($this->request->post()){
  224. $data = $this->request->post();
  225. $data["mid"]=Db::name("store_member")->where(["phone"=>$data["phone"],"status"=>1,"is_deleted"=>0])->value("id");
  226. if (!isset($data['mid']) || $data['mid']==''){
  227. $this->error('请选择有效用户');
  228. }
  229. $inventory = Db::name($this->table)->where('id',$data['id'])->value('inventory');
  230. $info = Db::name($this->table)->where('id',$data['id'])->find();
  231. $com = true;
  232. Db::startTrans();
  233. try {
  234. $array = [];
  235. for ($i=0;$i<$data['number'];$i++){
  236. //获取排名
  237. $rank = getRanking($data['id'])+1;
  238. $tag = getTag($data['id'],$rank,$inventory);
  239. saveRanking($data['id']);
  240. $company = '江苏栩贝文化有限公司';
  241. $hash = getCompanyHash($data['id']);
  242. $company_hash = $hash['hash'];
  243. $company_hash_time = $hash['create_at'];
  244. $tokenid = $hash['tokenid'];
  245. Db::name('hash')->where('hash',$hash['hash'])->update(['status'=>1]);
  246. $collectors_hash = '';
  247. $date = [
  248. 'order_no'=>get_order_sn(),
  249. 'tag'=>$tag,
  250. 'mid'=>$data['mid'],
  251. 'c_id'=>$data['id'],
  252. 'name'=>$info['name'],
  253. 'cover'=>$info['cover'],
  254. 'type'=>$info['type'],
  255. 'pro_info'=>json_encode($info,true),
  256. 'company'=>$company,
  257. 'company_hash'=>$company_hash,
  258. 'company_hash_time'=>$company_hash_time,
  259. 'ddcid'=>$tokenid,
  260. 'collectors_hash'=>$collectors_hash,
  261. 'collectors_hash_time'=>''
  262. ];
  263. $array[] = $date;
  264. }
  265. Db::name('store_order_info')->insertAll($array);
  266. Db::commit();
  267. } catch (\Exception $e){
  268. Db::rollback();
  269. $com = false;
  270. }
  271. if ($com){
  272. //减掉库存
  273. loseCollectionInventory($data['id'],$data['number']);
  274. $this->success('赠送成功');
  275. }else{
  276. $this->error('赠送失败');
  277. }
  278. }else{
  279. $id=$this->request->get('id');
  280. $this->assign('id',$id);
  281. // $user = Db::name('store_member')->where('is_deleted',0)->field('id,name,phone')->select();
  282. // $this->assign('user',$user);
  283. $this->fetch();
  284. }
  285. }
  286. public function hash(){
  287. if($this->request->post()){
  288. $id = $this->request->post('id');
  289. $number = $this->request->post('number');
  290. if ($number<=0){
  291. $this->error('数量错误');
  292. }
  293. if (Db::name('store_collection')->where('id',$id)->setInc('casting_num',$number)){
  294. $redis = new Redis();
  295. $redis->Incrby('castingHash_'.$id,$number);
  296. $this->success('增加成功,正在铸造中');
  297. }
  298. $this->error('增加失败,请稍后重试');
  299. }else{
  300. $id=$this->request->get('id');
  301. $this->assign('id',$id);
  302. $this->fetch();
  303. }
  304. }
  305. /**
  306. * 批量赠送
  307. * @auth true
  308. * @throws \think\Exception
  309. * @throws \think\exception\PDOException
  310. */
  311. public function import()
  312. {
  313. list($msec, $sec) = explode(' ', microtime());
  314. $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); //毫秒值
  315. $get = $this->request->get();
  316. $import_path = $_SERVER['DOCUMENT_ROOT'].'/'.$get['path'];
  317. $url = $get['url'];
  318. $c_id = $get['c_id'];
  319. if (getConfigValue('storage_type')=='oss'){
  320. $save_dir = "./upload/excle/"; // 服务资源目录
  321. $filename = date('Ymd').time().".xlsx"; // 自定义名称
  322. $res = $this->getFile($url,$save_dir,$filename,1);
  323. $import_path = $_SERVER['DOCUMENT_ROOT'].'/upload/excle/'.$res;
  324. }
  325. $info = getCollectionInfoHash($c_id);
  326. $num = 1;
  327. try {
  328. $objReader =\PHPExcel_IOFactory::createReader('Excel2007');
  329. $objExcel = $objReader->load($import_path);
  330. $list = $objExcel->getActiveSheet()->toArray();
  331. $success = 0;
  332. $number = 0;
  333. $array = array();
  334. foreach ($list as $k=>$v){
  335. if($k>$num-1){
  336. if(array_filter($v)){
  337. $data=[];
  338. foreach ($v as $kk=>$vv){
  339. $data[IntToChr($kk)]=trim($vv);
  340. }
  341. $a['phone'] = $data['A'];
  342. $a['number'] = $data['B'];
  343. array_push($array,$a);
  344. $number = $number+$data['B'];
  345. }
  346. }
  347. }
  348. $redis = new Redis();
  349. $zhuzao_count = $redis->Llen('collectionHash_'.$c_id);
  350. if ($zhuzao_count<$number){
  351. $this->error('铸造的的数量不足,无法赠送',[],3);
  352. }
  353. $error = 0;
  354. $phone_error = array();
  355. foreach ($array as &$v){
  356. $member = Db::name('store_member')->where('phone',$v['phone'])->find();
  357. if (!$member){
  358. $error = $error+1;
  359. array_push($phone_error,$v['phone']);
  360. }else{
  361. $array1 = [];
  362. for ($i=0;$i<$v['number'];$i++){
  363. //获取排名
  364. $rank = getRanking($c_id)+1;
  365. $tag = getTag($c_id,$rank,$info['inventory']);
  366. saveRanking($c_id);
  367. $company = '江苏栩贝文化有限公司';
  368. $hash = getCompanyHash($c_id);
  369. $company_hash = $hash['hash'];
  370. $company_hash_time = $hash['create_at'];
  371. $tokenid = $hash['tokenid'];
  372. Db::name('hash')->where('hash',$hash['hash'])->update(['status'=>1]);
  373. $collectors_hash = '';
  374. $date = [
  375. 'order_no'=>get_order_sn(),
  376. 'tag'=>$tag,
  377. 'mid'=>$member['id'],
  378. 'c_id'=>$c_id,
  379. 'name'=>$info['name'],
  380. 'cover'=>$info['cover'],
  381. 'type'=>$info['type'],
  382. 'pro_info'=>json_encode($info,true),
  383. 'company'=>$company,
  384. 'company_hash'=>$company_hash,
  385. 'company_hash_time'=>$company_hash_time,
  386. 'ddcid'=>$tokenid,
  387. 'collectors_hash'=>$collectors_hash,
  388. 'collectors_hash_time'=>''
  389. ];
  390. $array1[] = $date;
  391. }
  392. if (Db::name('store_order_info')->insertAll($array1)){
  393. loseCollectionInventory($c_id,$v['number']);
  394. $success +=1;
  395. }else{
  396. $error = $error+1;
  397. }
  398. }
  399. }
  400. if ($error<1){
  401. $this->success('成功');
  402. }else{
  403. $this->error('失败',['error'=>$error,'success'=>$success,'phone_error'=>$phone_error],2);
  404. }
  405. } catch (\think\exception\ValidateException $e) {
  406. $this->error($e->getMessage());
  407. }
  408. }
  409. /**
  410. * 批量赠送vip
  411. * @auth true
  412. * @throws \think\Exception
  413. * @throws \think\exception\PDOException
  414. */
  415. public function import2()
  416. {
  417. list($msec, $sec) = explode(' ', microtime());
  418. $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); //毫秒值
  419. $get = $this->request->get();
  420. $import_path = $_SERVER['DOCUMENT_ROOT'].'/'.$get['path'];
  421. $url = $get['url'];
  422. $c_id = $get['c_id'];
  423. if (getConfigValue('storage_type')=='oss'){
  424. $save_dir = "./upload/excle2/"; // 服务资源目录
  425. $filename = date('Ymd').time().".xlsx"; // 自定义名称
  426. $res = $this->getFile($url,$save_dir,$filename,1);
  427. $import_path = $_SERVER['DOCUMENT_ROOT'].'/upload/excle2/'.$res;
  428. }
  429. $num = 1;
  430. try {
  431. $objReader =\PHPExcel_IOFactory::createReader('Excel2007');
  432. $objExcel = $objReader->load($import_path);
  433. $list = $objExcel->getActiveSheet()->toArray();
  434. $success = 0;
  435. $number = 0;
  436. $array = array();
  437. foreach ($list as $k=>$v){
  438. if($k>$num-1){
  439. if(array_filter($v)){
  440. $data=[];
  441. foreach ($v as $kk=>$vv){
  442. $data[IntToChr($kk)]=trim($vv);
  443. }
  444. $a['phone'] = $data['A'];
  445. array_push($array,$a);
  446. }
  447. }
  448. }
  449. $error = 0;
  450. $phone_error = array();
  451. $array_data=array();
  452. foreach ($array as &$v){
  453. $member = Db::name('store_member')->where('phone',$v['phone'])->value("id");
  454. // $store_collection_tree=Db::name("store_collection")->where(["id"=>$c_id])->value("tree");
  455. // if($store_collection_tree && strpos($store_collection_tree,"|".$member."|")!==false){
  456. // break;
  457. // }
  458. if(!$member){
  459. $error = $error+1;
  460. array_push($phone_error,$v['phone']);
  461. }else{
  462. $success +=1;
  463. array_push($array_data,$member);
  464. }
  465. }
  466. if($success){
  467. $store_collection_tree=Db::name("store_collection")->where(["id"=>$c_id])->value("tree");
  468. $tree=implode("|",$array_data);
  469. if($store_collection_tree){
  470. Db::name("store_collection")->where(["id"=>$c_id])->update(["tree"=>$store_collection_tree.$tree."|"]);
  471. }else{
  472. Db::name("store_collection")->where(["id"=>$c_id])->update(["tree"=>"|".$tree."|"]);
  473. }
  474. }
  475. if ($error<1){
  476. $this->success('成功');
  477. }else{
  478. $this->error('失败',['error'=>$error,'success'=>$success,'phone_error'=>$phone_error],2);
  479. }
  480. } catch (\think\exception\ValidateException $e) {
  481. $this->error($e->getMessage());
  482. }
  483. }
  484. /**
  485. * 导出EXCL
  486. * @remark 根据WHERE条件导出EXCL
  487. * @param array $post 查询条件所需值
  488. * @return array
  489. */
  490. public function get_excl()
  491. {
  492. set_time_limit(300);
  493. $list = json_decode($this->request->get('phone'),true);
  494. $export = [];
  495. if (is_array($list)) {
  496. foreach ($list as $index => $item) {
  497. $export[] = [
  498. $item
  499. ];
  500. }
  501. }
  502. PHPExcelService::setExcelHeader(['手机号'])
  503. ->setExcelTile('错误手机号', '错误手机号', '手机号', time())
  504. ->setExcelContent($export)
  505. ->ExcelSave();
  506. }
  507. /**
  508. * 奖品管理
  509. * @remark 根据WHERE条件导出EXCL
  510. * @param array $post 查询条件所需值
  511. * @return array
  512. */
  513. public function prize_list(){
  514. $id=$this->request->get('id');
  515. $this->c_id = $id;
  516. $this->title = '奖品列表';
  517. $query = $this->_query($this->table2)->where('coll_id',$id)->where('is_del',1);
  518. $query->like('name');
  519. $query->order('id desc')->page();
  520. }
  521. /**
  522. * 数据列表处理
  523. * @auth true
  524. * @menu true
  525. * @param array $data
  526. * @throws \think\db\exception\DataNotFoundException
  527. * @throws \think\db\exception\ModelNotFoundException
  528. * @throws \think\exception\DbException
  529. */
  530. protected function _prize_list_page_filter(&$data)
  531. {
  532. foreach ($data as &$v){
  533. if ($v['is_prize']==1){
  534. $v['info'] = Db::name('store_collection')
  535. ->where('id',$v['prize'])
  536. ->field('id,name,cover,now_inventory,status')
  537. ->find();
  538. $v['info']['now_inventory'] = getCollectionInventory($v['prize']);
  539. }
  540. }
  541. //dump($data);die();
  542. }
  543. /**
  544. * 添加奖品
  545. * @auth true
  546. * @menu true
  547. * @throws \think\Exception
  548. * @throws \think\db\exception\DataNotFoundException
  549. * @throws \think\db\exception\ModelNotFoundException
  550. * @throws \think\exception\DbException
  551. * @throws \think\exception\PDOException
  552. */
  553. public function add_prize()
  554. {
  555. $id=$this->request->get('c_id');
  556. $this->c_id = $id;
  557. $this->title = '添加奖品';
  558. if($this->request->post()){
  559. if (Db::name($this->table2)->insert($this->request->post())){
  560. $this->success('添加成功');
  561. }
  562. $this->error('添加失败');
  563. }else{
  564. $prize = Db::name('store_collection')
  565. ->where('type',4)
  566. ->where('is_deleted',0)
  567. ->where('status',1)
  568. ->field('id,name')
  569. ->select();
  570. $this->prize = $prize;
  571. $this->_form($this->table, 'add_prize');
  572. }
  573. }
  574. /**
  575. * 添加奖品
  576. * @auth true
  577. * @menu true
  578. * @throws \think\Exception
  579. * @throws \think\db\exception\DataNotFoundException
  580. * @throws \think\db\exception\ModelNotFoundException
  581. * @throws \think\exception\DbException
  582. * @throws \think\exception\PDOException
  583. */
  584. public function edit_prize()
  585. {
  586. $cid=$this->request->get('c_id');
  587. $this->c_id = $cid;
  588. $this->title = '编辑奖品';
  589. if($this->request->post()){
  590. $post = $this->request->post();
  591. $post['update_at'] = date('Y-m-d H:i:s');
  592. if (Db::name($this->table2)->where('id',$post['id'])->update($post)){
  593. $this->success('编辑成功');
  594. }
  595. $this->error('编辑失败');
  596. }else{
  597. $id = $this->request->get('id');
  598. $this->vo = Db::name($this->table2)->where('id',$id)->find();
  599. $prize = Db::name('store_collection')
  600. ->where('type',4)
  601. ->where('is_deleted',0)
  602. ->where('status',1)
  603. ->field('id,name')
  604. ->select();
  605. $this->prize = $prize;
  606. $this->_form($this->table, 'add_prize');
  607. }
  608. }
  609. /**
  610. * 禁用
  611. * @auth true
  612. * @menu true
  613. * @throws \think\Exception
  614. * @throws \think\exception\PDOException
  615. */
  616. public function forbid2()
  617. {
  618. $this->_save($this->table2, ['status' => '0']);
  619. }
  620. /**
  621. * 启用
  622. * @auth true
  623. * @menu true
  624. * @throws \think\Exception
  625. * @throws \think\exception\PDOException
  626. */
  627. public function enable2()
  628. {
  629. $this->_save($this->table2, ['status' => 1]);
  630. }
  631. /**
  632. * 删除
  633. * @auth true
  634. * @menu true
  635. * @throws \think\Exception
  636. * @throws \think\exception\PDOException
  637. */
  638. public function del2()
  639. {
  640. $this->_save($this->table2, ['is_del' => 0]);
  641. }
  642. public function detail(){
  643. $id=$this->request->get('id');
  644. $this->title = Db::name($this->table)->where('id',$id)->value('name').'--铸造明细';
  645. $query = $this->_query('hash')->where('goods_id',$id);
  646. $query->dateBetween('create_at')->order('id desc')->page();
  647. $this->fetch();
  648. }
  649. public function curlRequest($url, $headers = [], $body = [], $method = "GET")
  650. {
  651. $ch = curl_init();
  652. curl_setopt($ch, CURLOPT_URL, $url);
  653. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);//设置请求头
  654. curl_setopt($ch, CURLOPT_POSTFIELDS, $body);//设置请求体
  655. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //定义请求类型
  656. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  657. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  658. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  659. curl_setopt($ch, CURLOPT_HTTP_VERSION, 'CURL_HTTP_VERSION_1_1');
  660. $output = curl_exec($ch);
  661. curl_close($ch);
  662. return $output;
  663. }
  664. /**
  665. * 下载文件到服务器
  666. * addtime 2020年8月28日 18:38:43
  667. */
  668. function getFile($url, $save_dir = '', $filename = '', $type = 0)
  669. {
  670. if (trim($url) == '') {
  671. return false;
  672. }
  673. if (trim($save_dir) == '') {
  674. $save_dir = './';
  675. }
  676. if (0 !== strrpos($save_dir, '/')) {
  677. $save_dir.= '/';
  678. }
  679. //创建保存目录
  680. if (!file_exists($save_dir) && !mkdir($save_dir, 0777, true)) {
  681. return false;
  682. }
  683. //获取远程文件所采用的方法
  684. if ($type) {
  685. $ch = curl_init();
  686. $timeout = 5;
  687. curl_setopt($ch, CURLOPT_URL, $url);
  688. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  689. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  690. $content = curl_exec($ch);
  691. curl_close($ch);
  692. } else {
  693. ob_start();
  694. readfile($url);
  695. $content = ob_get_contents();
  696. ob_end_clean();
  697. }
  698. $size = strlen($content);
  699. //文件大小
  700. $fp2 = @fopen($save_dir . $filename, 'a');
  701. fwrite($fp2, $content);
  702. fclose($fp2);
  703. unset($content, $url);
  704. return $filename;
  705. }
  706. }