Goodsfcode.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * ============================================================================
  12. * 数据层模型
  13. */
  14. class Goodsfcode extends BaseModel
  15. {
  16. /**
  17. * 插入数据
  18. * @access public
  19. * @author csdeshang
  20. * @param array $data 参数内容
  21. * @return boolean
  22. */
  23. public function addGoodsfcodeAll($data)
  24. {
  25. return Db::name('goodsfcode')->insertAll($data);
  26. }
  27. /**
  28. * 取得F码列表
  29. * @access public
  30. * @author csdeshang
  31. * @param type $condition 条件
  32. * @param type $order 排序
  33. * @return type
  34. */
  35. public function getGoodsfcodeList($condition, $order = 'goodsfcode_state asc,goodsfcode_id asc')
  36. {
  37. return Db::name('goodsfcode')->where($condition)->order($order)->select()->toArray();
  38. }
  39. /**
  40. * 删除F码
  41. * @access public
  42. * @author csdeshang
  43. * @param type $condition 条件
  44. * @return bool
  45. */
  46. public function delGoodsfcode($condition)
  47. {
  48. return Db::name('goodsfcode')->where($condition)->delete();
  49. }
  50. /**
  51. * 取得F码
  52. * @access public
  53. * @author csdeshang
  54. * @param type $condition 条件
  55. * @return bool
  56. */
  57. public function getGoodsfcode($condition)
  58. {
  59. return Db::name('goodsfcode')->where($condition)->find();
  60. }
  61. /**
  62. * 更新F码
  63. * @access public
  64. * @author csdeshang
  65. * @param array $data 更新数据
  66. * @param array $condition 条件
  67. * @return bool
  68. */
  69. public function editGoodsfcode($data, $condition)
  70. {
  71. return Db::name('goodsfcode')->where($condition)->update($data);
  72. }
  73. /**
  74. * 更新F码为使用状态
  75. * @param int $goodsfcode_id
  76. */
  77. public function updateGoodsfcode($goodsfcode_id)
  78. {
  79. $update = $this->editGoodsfcode(array('goodsfcode_state' => 1), array('goodsfcode_id' => $goodsfcode_id));
  80. if (!$update) {
  81. return ds_callback(false, '更新F码使用状态失败goodsfcode_id:' . $goodsfcode_id);
  82. } else {
  83. return ds_callback(true);
  84. }
  85. }
  86. /**
  87. * 生成商品F码
  88. */
  89. public function createGoodsfcode($param)
  90. {
  91. $insert = array();
  92. for ($i = 0; $i < $param['goodsfcode_count']; $i++) {
  93. $array = array();
  94. $array['goods_commonid'] = $param['goods_commonid'];
  95. $array['goodsfcode_code'] = strtoupper($param['goodsfcode_prefix']) . mt_rand(100000, 999999);
  96. $insert[$array['goodsfcode_code']] = $array;
  97. }
  98. if (!empty($insert)) {
  99. $insert = array_values($insert);
  100. $insert = $this->addGoodsfcodeAll($insert);
  101. if (!$insert) {
  102. return ds_callback(false, '生成商品F码失败goods_commonid:' . $param['goods_commonid']);
  103. }
  104. }
  105. return ds_callback(true);
  106. }
  107. }