Card.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace app\allwin\widget;
  3. use app\common\facade\WechatMp;
  4. class Card{
  5. //新增会员卡
  6. public static function create(array $param){
  7. $wechat = WechatMp::isTypes($param['member_miniapp_id']);
  8. $attributes = [
  9. 'prerogative' => $param['prerogative'],
  10. 'auto_activate' => true,
  11. 'supply_bonus' => false,
  12. 'supply_balance' => false,
  13. 'custom_cell1' => [
  14. 'name' => '买单',
  15. 'tips' => '立即进入',
  16. 'app_brand_user_name' => $param['gh_id'].'@app',
  17. 'app_brand_pass' => '/pages/cardbao/index',
  18. ],
  19. 'custom_cell2' => [
  20. 'name' => '会员中心',
  21. 'tips' => '立即进入',
  22. 'app_brand_user_name' => $param['gh_id'].'@app',
  23. 'app_brand_pass' => '/pages/cardbao/user',
  24. ],
  25. 'base_info' => [
  26. 'logo_url' => $param['picture'],
  27. 'brand_name' => $param['brand_name'],
  28. 'title' => $param['title'],
  29. 'color' => $param['color'],
  30. 'notice' => $param['notice'],
  31. 'description' => $param['description'],
  32. 'sku' => ['quantity' => $param['quantity']],
  33. 'date_info' => empty($param['end_time']) ? ['type' => 'DATE_TYPE_PERMANENT'] : ['type' => 'DATE_TYPE_FIX_TIME_RANGE', 'begin_timestamp' => $param['start_time'], 'end_timestamp' => $param['end_time']],
  34. 'code_type' => 'CODE_TYPE_TEXT',
  35. 'custom_url_name' => '账单',
  36. 'custom_url_sub_title' => '立即进入',
  37. 'custom_app_brand_user_name' => $param['gh_id'].'@app',
  38. 'custom_app_brand_pass' => '/pages/cardbao/index',
  39. ],
  40. ];
  41. $result = $wechat->card->create($cardType = 'MEMBER_CARD',$attributes);
  42. return $result;
  43. }
  44. //修改会员卡
  45. public static function update(array $param,$cardId,$state){
  46. $wechat = WechatMp::isTypes($param['member_miniapp_id']);
  47. $attributes = [
  48. 'prerogative' => $param['prerogative'],
  49. 'base_info' => [
  50. 'logo_url' => $param['picture'],
  51. 'title' => $param['title'],
  52. 'color' => $param['color'],
  53. 'notice' => $param['notice'],
  54. 'description' => $param['description'],
  55. ],
  56. ];
  57. if( $state == 1){
  58. $attributes['base_info']['date_info'] = ['type' => 'DATE_TYPE_FIX_TIME_RANGE', 'begin_timestamp' => $param['start_time'], 'end_timestamp' => $param['end_time']];
  59. }
  60. $rel = $wechat->card->update($cardId,$cardType = 'MEMBER_CARD',$attributes);
  61. return $rel;
  62. }
  63. //删除会员卡
  64. public static function delete($cardId,$member_miniapp_id){
  65. $wechat = WechatMp::isTypes($member_miniapp_id);
  66. return $wechat->card->delete($cardId);
  67. }
  68. //详情
  69. public static function info($cardId,$member_miniapp_id){
  70. $wechat = WechatMp::isTypes($member_miniapp_id);
  71. return $wechat->card->get($cardId);
  72. }
  73. //增加库存
  74. public static function increaseStock($cardId,$amount,$member_miniapp_id){
  75. $wechat = WechatMp::isTypes($member_miniapp_id);
  76. return $wechat->card->increaseStock($cardId,$amount);
  77. }
  78. //减少库存
  79. public static function reductStock($cardId,$amount,$member_miniapp_id){
  80. $wechat = WechatMp::isTypes($member_miniapp_id);
  81. return $wechat->card->reductStock($cardId,$amount);
  82. }
  83. //设置卡券失效
  84. public static function disable($cardId,$code,$member_miniapp_id){
  85. $wechat = WechatMp::isTypes($member_miniapp_id);
  86. return $wechat->card->disable($code,$cardId);
  87. }
  88. //获取用户已领卡券
  89. public static function getUserCards($cardId,$openid,$member_miniapp_id){
  90. $wechat = WechatMp::isTypes($member_miniapp_id);
  91. return $wechat->card->getUserCards($openid,$cardId);
  92. }
  93. }