ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` https://blog.csdn.net/weixin_39893205/article/details/111656809?depth_1-utm_source=distribute.pc_relevant_bbs_down.none-task--2~all~first_rank_v2~rank_v29-6.nonecase ``` ``` https://blog.csdn.net/qq_37970345/article/details/72832093?dist_request_id=1328603.60642.16152114426255623&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control namespace app\\index\\controller; use think\\Controller; use think\\Cache; class Index extends Controller {     /\*\*      \* 首页      \* \*/     public function index(){         $fp = fopen("lock.txt", "w+");         if(flock($fp,LOCK_EX))   //锁定当前指针,,,         {             //..处理订单             $stock = $this->findStock();             if($stock > 0){                 $this->setDec();             }else{                 return '抢购失败';             }             return $stock;             flock($fp,LOCK_UN);         }         fclose($fp);     }     /\*\*      \* 查询数据库库存      \* \*/     public function findStock(){         $res = db('info')->where('id',1)->field('stock')->lock(true)->find();         return $res['stock'];     }     /\*\*      \* 减少库存操作      \* \*/     public function setDec(){         $res = db('info')->where('id',1)->setDec('stock',1);         return $res;     } } ```