MerchantMiniprogram.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace app\models\merchant;
  3. use crmeb\basic\BaseModel;
  4. use crmeb\traits\ModelTrait;
  5. use think\db\exception\DbException;
  6. class MerchantMiniprogram extends BaseModel
  7. {
  8. /**
  9. * 数据表主键
  10. * @var string
  11. */
  12. protected $pk = 'id';
  13. /**
  14. * 模型名称
  15. * @var string
  16. */
  17. protected $name = 'merchant_miniprogram';
  18. use ModelTrait;
  19. public static function vaildWhere()
  20. {
  21. return self::where('is_del', 0);
  22. }
  23. /**
  24. * 删除小程序绑定记录
  25. * @param $mer_id
  26. * @return bool
  27. */
  28. public static function delMiniprogram($mer_id)
  29. {
  30. try {
  31. if (!self::vaildWhere()->where(['mer_id' => $mer_id])->find()) {
  32. return self::setErrorInfo('绑定记录未找到或已删除');
  33. }
  34. } catch (DbException $e) {
  35. return self::setErrorInfo($e->getMessage());
  36. }
  37. $res = self::where('mer_id', $mer_id)->update(['is_del' => 1, 'update' => time()]);
  38. if ($res) {
  39. return true;
  40. } else {
  41. return self::setErrorInfo('删除失败');
  42. }
  43. }
  44. public static function checkOne($app_id, $sign, $sign_time)
  45. {
  46. $app_secret = self::where(['appid' => $app_id])->value('boofly_app_secret');
  47. if (!$app_secret) {
  48. return false;
  49. }
  50. return $sign == self::sign($app_id, $app_secret, $sign_time);
  51. }
  52. public static function sign($app_id, $app_secret, $time)
  53. {
  54. return md5(md5($app_id . $time . $app_secret . $time . $app_id . $app_secret));
  55. }
  56. }