<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## 數據庫操作類 ~~~ <?php /** * Created by gather * Email: chenruiqiang@yd-x.com * Phone: 16601180687 * Copyright:源動互通(北京)科技有限公司 * Create Time: 2018/6/6 13:55 */ namespace test; class DB{ private static $dbcon = false; private $host; private $port; private $user; private $pass; private $db; private $charset; private $link; public function __construct(){ $this->host = "127.0.0.1"; $this->port = "3306"; $this->user = "root"; $this->pass = "xyq07041103"; $this->db = "email"; $this->charset = "utf8"; $this->db_connect(); $this->db_usedb(); $this->db_charset(); } //連接數據庫 private function db_connect(){ //$host = '', $user = '', $password = '', $database = '', $port = '', $socket = '' $this->link = mysqli_connect($this->host,$this->user,$this->pass,$this->db,$this->port); if (!$this->link){ echo "數據庫連接失敗<br>"; echo "錯誤編碼".mysqli_errno($this->link)."<br>"; echo "錯誤信息".mysqli_error($this->link)."<br>"; exit(); } } //設置字符集 public function db_charset(){ mysqli_query($this->link,"set names {$this->charset}"); } //選擇數據庫 public function db_usedb(){ mysqli_query($this->link,"use {$this->db}"); } //私有的克隆 private function __clone(){ // TODO: Implement __clone() method. die("clone is not allowed"); } //公用靜態方法 public static function getInstance(){ if (self::$dbcon == false){ self::$dbcon = new self; } return self::$dbcon; } //執行sql語句的方法 public function query($sql){ $res = mysqli_query($this->link,$sql); if(!$res){ echo "sql語句執行失敗<br>"; echo "錯誤編碼是".mysqli_errno($this->link)."<br>"; echo "錯誤信息是".mysqli_error($this->link)."<br>"; } return $res; } //獲得最后一條記錄id public function getInsertId(){ return mysqli_insert_id($this->link); } /** * 查詢莫個字段 * @param $sql * @return string or int */ public function getOne($sql){ $query = $this->query($sql); return mysqli_free_result($query); } //獲取一行記錄,return array 一維數組 public function getRow($sql,$type="assoc"){ $query = $this->query($sql); if(!in_array($type,array("assoc",'array','row'))){ die("mysql_query error"); } $funcname = "mysqli_fetch_".$type; return $funcname($query); } //獲取一條記錄,前置條件通過資源獲取一條記錄 public function getFormSource($query,$type="assoc"){ if(!in_array($type,array("assoc","array","row"))){ die("mysqli_query error"); } $funcname = "mysqli_fetch_".$type; return $funcname($query); } //獲取多條數據,二維數組 public function getAll($sql){ $query = $this->query($sql); $list = array(); while ($r=$this->getFormSource($query)){ $list[] = $r; } return $list; } //選擇所有 public function selectAll($table,$where,$fields='*',$order='',$skip=0,$limit=1000){ if (is_array($where)){ foreach ($where as $key => $val){ if(is_numeric($val)){ $condition = $key.'='.$val; }else{ $condition = $key.'=\''.$val.'\''; } } }else{ $condition = $where; } if (!empty($order)){ $order = " order by ".$order; } $sql = "select $fields from $table where $condition $order limit $skip,$limit"; $query = $this->query($sql); $list = array(); while ($r=$this->getFormSource($query)){ $list[] = $r; } return $list; } public function insert($table,$data){ $key_str = ""; $v_str=""; foreach ($data as $key=>$v) { $key_str .= $key.','; $v_str .= "'$v'".','; } $key_str = trim($key_str,','); $v_str = trim($v_str,','); $sql = "insert into $table($key_str) values($v_str)"; $this->query($sql); return $this->getInsertId(); } public function deleteOne($table,$where){ if(is_array($where)){ foreach ($where as $key=>$val){ $condition = $key.'='.$val; } }else{ $condition = $where; } $sql = "delete from $table where $condition"; $this->query($sql); return mysqli_affected_rows($this->link); } public function deleteAll($table,$where){ if(is_array($where)){ foreach ($where as $key=>$val){ if(is_array($val)) { $condition = $key.' in('.implode(',',$val).')'; }else{ $condition = $key.'='.$val; } } }else{ $condition = $where; } $sql = "delete from $table where $condition"; $this->query($sql); return mysqli_affected_rows($this->link); } public function update($table,$data,$where,$limit=0){ $str = ''; foreach ($data as $key=>$v){ $str .= "$key='$v'".','; } $str = rtrim($str,','); if (is_array($where)){ foreach ($where as $key=>$val){ if(is_array($val)) { $condition = $key.' in('.implode(',',$val).')'; }else{ $condition = $key.'='.$val; } } }else{ $condition = $where; } if (empty($limit)){ $limit = " limit ".$limit; }else{ $limit = ''; } $sql = "update $table set $str where $condition $limit"; // var_dump($sql); $this->query($sql); return mysqli_affected_rows($this->link); } } ~~~ ## 數據表 ~~~ CREATE TABLE `order_queue` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `order_id` int(11) NOT NULL, `mobile` varchar(2) NOT NULL COMMENT '用戶手機號', `created_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `updated_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `status` tinyint(4) NOT NULL COMMENT '0未處理1已處理2處理中', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8mb4 ~~~ ## 增加訂單order.php文件 ~~~ <?php /** * Created by gather * Email: chenruiqiang@yd-x.com * Phone: 16601180687 * Copyright:源動互通(北京)科技有限公司 * Create Time: 2018/6/6 18:55 */ //這個文件主要是配送系統處理隊列中的訂單并進行標記的一個文件 require "DB.php"; use test\DB; $db=DB::getInstance(); //1)先把要處理的記錄更新為等待處理, $waiting = array('status'=>0); $data = array( 'status'=>2, ); $res_lock = $db->update('order_queue',$data,$waiting,2); //2)我們要選擇出剛剛咱們更新的這些數據,然后進行配送系統的處理。 if ($res_lock){ //選擇出要處理的訂單內容,有配貨系統處理 $res = $db->selectAll('order_queue',$data); //有配貨系統進行退貨處理 //把訂單更新已完成 $success = array( 'status'=>1, 'updated_at'=>date("Y-m-d H:i:s") ); $res_last = $db->update('order_queue',$success,$data,2); if ($res_last){ echo "Success:".$res_last; }else{ echo "Fail:".$res_last; } }else{ echo "沒有需要處理的數據"; } //3)處理過的更新為已完成。 ~~~ ## 處理訂單goods.php文件 ~~~ <?php /** * Created by gather * Email: chenruiqiang@yd-x.com * Phone: 16601180687 * Copyright:源動互通(北京)科技有限公司 * Create Time: 2018/6/6 18:55 */ //這個文件主要是配送系統處理隊列中的訂單并進行標記的一個文件 require "DB.php"; use test\DB; $db=DB::getInstance(); //1)先把要處理的記錄更新為等待處理, $waiting = array('status'=>0); $data = array( 'status'=>2, ); $res_lock = $db->update('order_queue',$data,$waiting,2); //2)我們要選擇出剛剛咱們更新的這些數據,然后進行配送系統的處理。 if ($res_lock){ //選擇出要處理的訂單內容,有配貨系統處理 $res = $db->selectAll('order_queue',$data); //有配貨系統進行退貨處理 //把訂單更新已完成 $success = array( 'status'=>1, 'updated_at'=>date("Y-m-d H:i:s") ); $res_last = $db->update('order_queue',$success,$data,2); if ($res_last){ echo "Success:".$res_last; }else{ echo "Fail:".$res_last; } }else{ echo "沒有需要處理的數據"; } //3)處理過的更新為已完成。 ~~~ ## shell 文件 good.sh ~~~ #!/bin/bash date "+%G-%m-%d %H:%M:%S" cd /Applications/XAMPP/xamppfiles/htdocs/study/order_queue/ php goods.php ~~~ ## 定時任務crontab 命令 crontab -e `*/1 * * * * /Applications/XAMPP/xamppfiles/htdocs/study/order_queue/good.sh >> /Applications/XAMPP/xamppfiles/htdocs/study/order_queue/log.log 2>&1`
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看