ShopGoods.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <?php
  2. namespace common\models;
  3. /**
  4. * This is the model class for table "{{%SHOP_GOODS}}".
  5. *
  6. * @property string $ID
  7. * @property string $GOODS_NAME 商品名称
  8. * @property string $CATE_ID 所属分类ID
  9. * @property string $TYPE 商品来源
  10. * @property string $GIFT_TYPE 商品类型
  11. * @property string $CATEGORY_TYPE 商品分类
  12. * @property string $SELL_TYPE 允许购买方式
  13. * @property int $GOODS_NO 商品编号
  14. * @property string $UNIT 单位
  15. * @property string $COVER 商品封面
  16. * @property int $IMAGES 商品图片
  17. * @property string $CONTENT 商品内容
  18. * @property string $SELL_PRICE_STANDARD 标准价格
  19. * @property int $PRICE_PV 价格PV
  20. * @property int $POINT 兑换积分
  21. * @property int $STORE_NUMS 库存
  22. * @property int $IS_DEL 是否删除
  23. * @property int $CREATED_AT 创建时间
  24. * @property int $UPDATED_AT 更新时间
  25. * @property int $DELETED_AT 删除时间
  26. * @property int $STATUS 状态
  27. * @property string $SORT 排序
  28. */
  29. class ShopGoods extends \common\components\ActiveRecord
  30. {
  31. const SALE_TYPE = [
  32. 1 => [
  33. 'id' => 1,
  34. 'name' => 'Account Balance', //余额购买
  35. 'label' => 'cash',
  36. 'language' => 'shopListAccountBalance',
  37. ],
  38. // 2 => [
  39. // 'id' => 2,
  40. // 'name' => '复消兑换',
  41. // ],
  42. // 3 => [
  43. // 'id' => 3,
  44. // 'name' => '兑换点数',
  45. // 'label' => 'exchange',
  46. // ],
  47. 4 => [
  48. 'id' => 4,
  49. 'name' => 'Travel Bonus',
  50. 'label' => 'tourism_points',
  51. 'language' => 'shopListPayTravelBonus',
  52. ],
  53. 5 => [
  54. 'id' => 5,
  55. 'name' => 'Car Fund',
  56. 'label' => 'garage_points',
  57. 'language' => 'shopListPayCarFund',
  58. ],
  59. 6 => [
  60. 'id' => 6,
  61. 'name' => 'Villa Fund',
  62. 'label' => 'villa_points',
  63. 'language' => 'shopListPayVillaFund',
  64. ],
  65. 7 => [
  66. 'id' => 7,
  67. 'name' => 'PayStack',
  68. 'label' => 'pay_stack',
  69. 'language' => 'saleTypePayStack',
  70. ],
  71. ];
  72. const GOODS_TYPE = [
  73. 1 =>[
  74. 'name'=>'国内商品',//国内商品
  75. 'discount'=>'50',
  76. 'language' => 'shopGoodTypeDomestic',
  77. ],
  78. 2 =>[
  79. 'name'=>'进口商品',//进口商品
  80. 'discount'=>'60',
  81. 'language' => 'shopGoodTypeImport',
  82. ],
  83. ];
  84. const STATUS_NAME = [
  85. 1 => 'On sale',//已上架
  86. 0 => 'Sold out',//已下架
  87. ];
  88. /**
  89. * @inheritdoc
  90. */
  91. public static function tableName()
  92. {
  93. return '{{%SHOP_GOODS}}';
  94. }
  95. /**
  96. * @inheritdoc
  97. */
  98. public function rules()
  99. {
  100. return [
  101. [['SELL_DISCOUNT','GOODS_NAME', 'CATE_ID','GIFT_TYPE', 'GOODS_NO', 'PRICE_PV','STORE_NUMS', 'SELL_TYPE', 'CATEGORY_TYPE', 'SELL_PRICE_STANDARD'], 'required'],
  102. [['STORE_NUMS'], 'integer'],
  103. [['PRICE_PV','POINT',/* 'SELL_TYPE',*/ 'CATEGORY_TYPE' ,'SELL_PRICE_STANDARD'], 'number'],
  104. [['ID','CATE_ID', 'GOODS_NO','GIFT_TYPE'], 'string', 'max' => 32],
  105. [['UNIT'], 'string', 'max' => 16],
  106. [['COVER', 'GOODS_NAME'], 'string', 'max' => 255],
  107. [['IMAGES','CONTENT'], 'string', 'max' => 4000],
  108. [['GOODS_NAME'], 'unique'],
  109. [['ID'], 'unique'],
  110. ];
  111. }
  112. /**
  113. * @inheritdoc
  114. */
  115. public function attributeLabels()
  116. {
  117. return [
  118. 'ID' => 'ID',
  119. 'GOODS_NAME' => '商品名称',
  120. 'CATE_ID' => '所属分类ID',
  121. // 'TYPE' => '商品来源',
  122. 'SELL_DISCOUNT' => '会员折扣',
  123. 'GIFT_TYPE' => '商品类型',
  124. 'CATEGORY_TYPE' => '商品分类',
  125. 'SELL_TYPE' => '出售方式',
  126. 'GOODS_NO' => '商品编号',
  127. 'UNIT' => '商品单位',
  128. 'COVER' => '商品封面',
  129. 'IMAGES' => '商品图片',
  130. 'CONTENT' => '商品内容',
  131. 'SELL_PRICE_STANDARD' => 'US price($)',
  132. 'PRICE_PV' => '价格PV',
  133. // 'POINT' => '兑换积分',
  134. 'STORE_NUMS' => '库存',
  135. 'STATUS' => '是否上架',
  136. 'IS_DEL' => '是否删除',
  137. 'CREATED_AT' => '创建时间',
  138. 'UPDATED_AT' => '更新时间',
  139. 'DELETED_AT' => '更新时间',
  140. 'SORT' => '排序',
  141. ];
  142. }
  143. /**
  144. * 判断提现状态
  145. * @param $nowStatus
  146. * @param $toStatus
  147. * @return string
  148. */
  149. public static function chkAuditStatus($nowStatus, $toStatus) {
  150. $statusName = self::STATUS_NAME;
  151. // $msg = 'The current product status is【' . $statusName[$nowStatus] . '】,cannot be set to【' . $statusName[$toStatus] . '】';// 当前商品状态为 无法设置为
  152. $msg = \Yii::t('ctx', 'shopSetProductStatusErrorNotice', [
  153. 'nowStatus' => $statusName[$nowStatus],
  154. 'newStatus' => $statusName[$toStatus]
  155. ]);
  156. switch ($toStatus) {
  157. // 下架
  158. case 0:
  159. if ($nowStatus == 1) {
  160. $msg = '';
  161. }
  162. break;
  163. //上架
  164. case 1:
  165. if ($nowStatus == 0) {
  166. $msg = '';
  167. }
  168. break;
  169. default:
  170. }
  171. return $msg;
  172. }
  173. /**
  174. * 支付方式
  175. * @return array
  176. */
  177. public static function payTypes(){
  178. return [
  179. 'cash'=>[
  180. 'name'=> \Yii::t('ctx', 'shopPayTypeCash')//余额支付
  181. ],
  182. // 'point'=>[
  183. // 'name'=>'积分支付' //积分支付
  184. // ],
  185. // 'exchange' => [
  186. // 'name' => '积分点数'
  187. // ],
  188. // 'tourism_points'=>[
  189. // 'name'=>'Travel Bonus'
  190. // ],
  191. 'garage_points' => [
  192. 'name' => \Yii::t('ctx', 'shopPayTypeGaragePoints')
  193. ],
  194. 'villa_points' => [
  195. 'name' => \Yii::t('ctx', 'shopPayTypeVillaFund')
  196. ],
  197. 'pay_stack' => [
  198. 'name' => 'PayStack'
  199. ],
  200. ];
  201. }
  202. // 获取商品类型
  203. public static function getGiftType() {
  204. return [
  205. 1 =>[
  206. 'name'=>\Yii::t('ctx', 'shopList1stPurchase'),//报单区
  207. ],
  208. 2 =>[
  209. 'name'=>\Yii::t('ctx', 'shopListRepeatPurchase'),//复消区
  210. ],
  211. // 3 =>[
  212. // 'name'=>\Yii::t('ctx', 'shopListEntryArea'),//工作室报单
  213. // ],
  214. // 4 =>[
  215. // 'name'=>\Yii::t('ctx', 'shopListResellingArea'),//工作室复消
  216. // ],
  217. ];
  218. }
  219. // 获取分类类型
  220. public static function getCategoryType() {
  221. return [
  222. [
  223. 'id' => 1,
  224. 'name' => \Yii::t('ctx', 'shopListStandardProducts'),//普通商品
  225. 'sell_type' => [
  226. self::SALE_TYPE[1],
  227. // self::SALE_TYPE[3],
  228. self::SALE_TYPE[7],
  229. ]
  230. ],
  231. // [
  232. // 'id' => 4,
  233. // 'name' => 'Travel bonus products',//旅游积分商品
  234. // 'sell_type' => [
  235. // self::SALE_TYPE[4]
  236. // ]
  237. // ],
  238. [
  239. 'id' => 5,
  240. 'name' => \Yii::t('ctx', 'shopListCarFundProducts'),
  241. 'sell_type' => [
  242. self::SALE_TYPE[5]
  243. ]
  244. ],
  245. [
  246. 'id' => 6,
  247. 'name' => \Yii::t('ctx', 'shopListVillaFundProducts'),
  248. 'sell_type' => [
  249. self::SALE_TYPE[6]
  250. ]
  251. ],
  252. ];
  253. }
  254. public static function getSaleType(): array
  255. {
  256. return array_map(function ($item) {
  257. $item['name'] = \Yii::t('ctx', $item['language']);
  258. return $item;
  259. }, self::SALE_TYPE);
  260. }
  261. public static function getGoodType(): array
  262. {
  263. return array_map(function ($item) {
  264. $item['name'] = \Yii::t('ctx', $item['language']);
  265. return $item;
  266. }, self::GOODS_TYPE);
  267. }
  268. }