最近做了一个项目,其中有需求,要求我们实现此功能:商品成交时发送短信,下面小编贴出核心代码,方面大家以后学习。
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;
}
}
以上代码是小编给大家贴的核心的代码,代码还算简单,所以没给大家写太多的注释,大家在参考过程中遇到任何问题,欢迎给我留言,小编会及时回复大家的,在此非常感谢大家对硕编程网站的支持!
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!