最近做了一個項目,其中有需求,要求我們實現此功能:商品成交時發送短信,下面小編貼出核心代碼,方面大家以後學習。
html程式碼省略.....
Model程式碼省略.....
核心程式碼如下圖:
/* * ------------------------------------------------- * 修改状态 public * Author: lzp Time:-- * ------------------------------------------------- */ public function changeStateAction() { $id = $_REQUEST['id']; $result = $this->changeConfirmState($id); if ($result) { $this->success("修改成功"); } else { $this->error("修改失败"); } } private function changeConfirmState($id) { $reg = $this->priceModel->selectPrice(['id'=>['eq', $id]]); $rel = $this->demandModel->selectDemand(['id'=>['eq',$reg[]['demand_id']]]); $demand_id = $reg[]['demand_id']; $reg['demand'] = $this->priceModel->selectPrice(['demand_id'=>['eq',$demand_id]]); foreach ($reg['demand'] as $key => $value){ if($value['phone'] == $reg[]['phone']){ unset($reg['demand'][$key]); }else{ $new[] = $value['phone']; } } $new = [''=>'********']; if((time()-strtotime($rel[]['create_time']))> ){ echo "<script>alert('已超时!');history.back();</script>"; die; }else if(strtotime($rel[]['finish_time'])>){ echo "<script>alert('已成交!');history.back();</script>"; die; }else{ $data_demand = [ 'is_available' => , 'finish_time' => date("Y-m-d H:i:s") ]; $result['Price'] = $this->priceModel->savePrice( ['id'=>['eq',$id]], ['state'=>] ); $result['Demadn'] = $this->demandModel->saveDemand(['id'=>['eq',$reg[]['demand_id']]] , $data_demand); $mobile = implode(",", $new); $content = "此条需求已成交,下次再来哟!"; smsApp($mobile,$content); //发短信 return $result; } }
以上程式碼是小編給大家貼的核心的程式碼,程式碼還算簡單,所以沒給大家寫太多的註釋,大家在參考過程中遇到任何問題,歡迎給我留言,小編會及時回覆大家的,在此非常感謝大家對本站網站的支持!
以上就介紹了基於PHP實現商品成交時發送短信功能,包括了發送短信,php方面的內容,希望對PHP教程有興趣的朋友有所幫助。