Beispiel #1
0
 /**
  * @brief 发送到货通知邮件
  */
 function notify_send()
 {
     $smtp = new SendMail();
     $error = $smtp->getError();
     if ($error) {
         $return = array('isError' => true, 'message' => $error);
         echo JSON::encode($return);
         exit;
     }
     $notify_ids = IFilter::act(IReq::get('notifyid'));
     $message = '';
     if ($notify_ids && is_array($notify_ids)) {
         $ids = join(',', $notify_ids);
         $query = new IQuery("notify_registry as notify");
         $query->join = "right join goods as goods on notify.goods_id=goods.id left join user as u on notify.user_id = u.id";
         $query->fields = "notify.*,u.username,goods.name as goods_name,goods.store_nums";
         $query->where = "notify.id in(" . $ids . ")";
         $items = $query->find();
         //库存大于0,且处于未发送状态的 发送通知
         $succeed = 0;
         $failed = 0;
         $tb_notify_registry = new IModel('notify_registry');
         foreach ($items as $value) {
             $body = mailTemplate::notify(array('{goodsName}' => $value['goods_name'], '{url}' => IUrl::getHost() . IUrl::creatUrl('/site/products/id/' . $value['goods_id'])));
             $status = $smtp->send($value['email'], "到货通知", $body);
             if ($status) {
                 //发送成功
                 $succeed++;
                 $data = array('notify_time' => ITime::getDateTime(), 'notify_status' => '1');
                 $tb_notify_registry->setData($data);
                 $tb_notify_registry->update('id=' . $value['id']);
             } else {
                 //发送失败
                 $failed++;
             }
         }
     }
     $return = array('isError' => false, 'count' => count($items), 'succeed' => $succeed, 'failed' => $failed);
     echo JSON::encode($return);
 }