| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace app\common\library\ps;
- use app\common\model\ps\MarketLicense;
- use app\common\model\ps\Template;
- use think\Exception;
- /**
- * 单次购买:导入本厂库一次,确认套打后锁定,不可再套打。
- */
- class TemplateLicense
- {
- /**
- * 套打前校验
- * @param Template $template
- * @param int $factoryId
- * @throws Exception
- */
- public static function assertPrintable(Template $template, $factoryId)
- {
- if ((int)$template->is_system === 1) {
- return;
- }
- if ((int)$template->factory_id !== (int)$factoryId) {
- throw new Exception('模板不属于当前工厂');
- }
- if ($template->license_type === 'market_single' && (int)$template->locked === 1) {
- throw new Exception('该模板为单次购买,已使用过,不允许再次套打');
- }
- }
- /**
- * 确认套打后消耗单次授权
- * @param Template $template
- * @param int $factoryId
- */
- public static function consumeOnConfirm(Template $template, $factoryId)
- {
- if ($template->license_type !== 'market_single' || (int)$template->locked === 1) {
- return;
- }
- $template->save([
- 'locked' => 1,
- 'locked_time' => time(),
- ]);
- MarketLicense::where('factory_id', $factoryId)
- ->where('template_id', $template->id)
- ->where('license_type', 'single')
- ->update([
- 'remain_times' => 0,
- 'locked' => 1,
- 'used_time' => time(),
- ]);
- }
- }
|