|
@@ -6,6 +6,7 @@
|
|
|
|
|
|
namespace app\models\store;
|
|
|
|
|
|
+use app\admin\model\system\SystemStoreBill;
|
|
|
use app\models\system\SystemStore;
|
|
|
use crmeb\services\PHPExcelService;
|
|
|
use crmeb\traits\ModelTrait;
|
|
@@ -104,4 +105,43 @@ class Card extends BaseModel
|
|
|
{
|
|
|
return substr(md5(md5('lpk.zccy.rand' . rand(100000, 999999)) . rand(0, 100000)), 0, 16);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public static function sendCard($store_id, $card_code)
|
|
|
+ {
|
|
|
+ $card = self::where('code', $card_code)->find();
|
|
|
+ if (!$card) return self::setErrorInfo('礼品卡不存在');
|
|
|
+ if ($card['status'] != 0) return self::setErrorInfo('礼品卡不可赠送');
|
|
|
+ $card['store_id'] = $store_id;
|
|
|
+ $card['send_time'] = time();
|
|
|
+ $card['status'] = 1;
|
|
|
+ $res = $card->save();
|
|
|
+ if ($res) return true;
|
|
|
+ else return self::setErrorInfo('礼品卡送出失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function checkCard($store_id, $card_code, $password)
|
|
|
+ {
|
|
|
+ $card = self::where('code', $card_code)->find();
|
|
|
+ if (!$card) return self::setErrorInfo('礼品卡不存在');
|
|
|
+ if ($card['status'] != 1) return self::setErrorInfo('礼品卡不可核销');
|
|
|
+ if ($card['password'] !== $password) return self::setErrorInfo('卡密错误');
|
|
|
+ $card['check_store_id'] = $store_id;
|
|
|
+ $card['check_time'] = time();
|
|
|
+ $card['status'] = 2;
|
|
|
+ $res = $card->save() && self::sendAward($card);
|
|
|
+ if ($res) return true;
|
|
|
+ else return self::setErrorInfo(self::getErrorInfo('核销失败'));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function sendAward($card)
|
|
|
+ {
|
|
|
+ if ($card['store_id'] && $card['store_award'] && SystemStore::be(['id' => $card['store_id']])) {
|
|
|
+ $store = SystemStore::get($card['store_id']);
|
|
|
+ $mark = '赠送的礼品卡' . $card['name'] . '(' . $card['id'] . ')核销成功,获得佣金。';
|
|
|
+ SystemStoreBill::income('礼品卡佣金', $card['store_id'], 'brokerage_price', 'card_award', $card['store_award'], $card['id'], bcadd($store['brokerage_price'], $card['store_award'], 2), $mark);
|
|
|
+ SystemStore::bcInc($card['store_id'], 'brokerage_price', $card['store_award'], 'id');
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|