123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- /*
- |--------------------------------------------------------------------------
- | 获取优惠券
- |--------------------------------------------------------------------------
- */
- namespace Youzan\Src;
- use Dever;
- use Main\Lib\Wechat;
- use Main\Lib\Core;
- class Card
- {
- # 发送单条模板消息
- public function send()
- {
- $key = Dever::input('key');
- $project_id = Dever::input('project_id');
- $touser = Dever::input('touser');
- return $this->sendOne($key, $project_id, $touser);
- }
- # 发送单条模板消息
- public function sendOne($key, $project_id, $touser, $state = true)
- {
- if ($project_id > 0 && $key && $touser) {
- $info = Dever::db('youzan/card')->one(array('option_key' => $key, 'option_project_id' => $project_id));
- if ($info) {
- Dever::setInput('mobile', $touser);
- Dever::load('youzan/user.reg');
- $update = array();
- $update['project_id'] = $info['project_id'];
- $update['card_id'] = $info['id'];
- $update['touser'] = $touser;
- $where = array();
- $where['option_card_id'] = $info['id'];
- //$where['option_project_id'] = $info['project_id'];
- $where['option_touser'] = $update['touser'];
- $id = Dever::upinto('youzan/card_log', $where, $update);
- return Core::run($info['project_id'], 'card', 'card.sendAction', 'card.sendLog', 'youzan', $id, $state);
- }
- }
- return false;
- }
- public function sendAction($id)
- {
- $info = Dever::db('youzan/card_log')->one($id);
- if ($info) {
- $msg = Dever::db('youzan/card')->one($info['card_id']);
- $info['mobile'] = $info['touser'];
- $info['coupon_group_id'] = $msg['card_id'];
- return $info;
- } else {
- die;
- }
- }
- public function sendLog($project_id, $data, $id = false)
- {
- $info = Dever::db('youzan/card_log')->one($id);
- if ($info) {
- $update['where_id'] = $info['id'];
- $update['result'] = json_encode($data);
- if (!isset($data['error_response'])) {
- $update['status'] = 2;
- } else {
- $update['status'] = 3;
- }
- $update['num'] = $info['num'] + 1;
- Dever::db('youzan/card_log')->update($update);
- }
- }
- }
|