· 9 years ago · Jan 16, 2017, 04:12 PM
1<?php
2
3/**
4 * Created by PhpStorm.
5 * User: Volio
6 * Date: 2017/1/16
7 * Time: 22:37
8 */
9class Express extends Base
10{
11
12 public function command($command, $param, $message_id, $from, $chat, $date)
13 {
14 if ($command == "/express") {
15 $boolean = $this->checkParam($param);
16
17 if ($boolean) {
18 if ($this->saveSubscription($from["id"], $param[0]))
19 $str = "订阅æˆåŠŸï¼Œå¿«é€’æœ‰æ–°æ¶ˆæ¯å°†åŠæ—¶é€šçŸ¥";
20 else
21 $str = "系统异常,请ç¨åŽå†è¯•";
22 } else {
23 $str = "订阅失败,请检查快递å•å·æ˜¯å¦æ£ç¡®";
24 }
25
26 $this->telegram->sendMessage($chat["id"], $str, $message_id);
27 }
28 }
29
30 private function checkParam($param)
31 {
32 if (empty($param) != true) {
33 if (strlen($param[0]) == 12 && is_numeric($param[0])) {
34 return true;
35 }
36 }
37
38 return false;
39 }
40
41 private function saveSubscription($uid, $eid)
42 {
43 if ($this->db->has("express", ["AND" => ["uid" => $uid, "eid" => $eid]]))
44 return true;
45 else
46 return $this->db->insert("express", ["uid" => $uid, "eid" => $eid]);
47 }
48
49 public function install()
50 {
51 $sql = <<<SQL
52CREATE TABLE IF NOT EXISTS `express` (
53 `id` int(10) UNSIGNED NOT NULL,
54 `uid` int(10) UNSIGNED NOT NULL,
55 `eid` varchar(12) NOT NULL,
56 `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
57) ENGINE=InnoDB DEFAULT CHARSET=utf8;
58
59ALTER TABLE `express`
60 ADD PRIMARY KEY (`id`);
61
62ALTER TABLE `express`
63 MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;
64SQL;
65
66 $this->db->exec($sql);
67 }
68}