|
@@ -0,0 +1,75 @@
|
|
|
+<?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) {
|
|
|
+ $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_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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|